I’m trying to make a script that gives me the tray but when i hit the tray i want it to give me it does this what on my video of it
here the code of my Gui
local tool = game.Workspace.CupcakeTray
local player = game.Players.LocalPlayer
local cookie = script.Parent
cookie.MouseButton1Click:Connect(function()
for _, item in pairs(player.Character:GetChildren()) do
if item.Name == tool.Name then
item:Remove()
end
end
for _, item in pairs(player.Backpack:GetChildren()) do
if item.Name == tool.Name then
item:Remove()
end
end
local clonedTool = tool:Clone()
clonedTool.Parent = player.Backpack
end)
try this, i used Destroy() Instead of Remove() and added some fixes
local tool = game.Workspace:WaitForChild("CupcakeTray")
local player = game.Players.LocalPlayer
local cookie = script.Parent
cookie.MouseButton1Click:Connect(function()
if player.Character then
for _, item in pairs(player.Character:GetChildren()) do
if item.Name == tool.Name then
item:Destroy()
end
end
end
if player.Backpack then
for _, item in pairs(player.Backpack:GetChildren()) do
if item.Name == tool.Name then
item:Destroy()
end
end
end
local clonedTool = tool:Clone()
clonedTool.Parent = player.Backpack
end)
what the issue is when I click the button in it give me the tool in it kind of stick to the where the pool at on the video instead of just giving me the tool that all I know that what it is doing