I get teleported when I give myself a tool

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)

it still does the same thing

can i get a better understanding on what the issue is?

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

It’s because your tools is anchored.

Just un-anchor the tool and put it in ReplicatedStorage, if it’s serving a purpose just un-anchor the tool programmatically after cloning.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.