Copying a tool into Backpack upon MouseClick

Hello Developers!

What i want to do is making a tool copy into the player’s backpack after clicking a part. I tried both type of scripts (local and normal) and it doesn’t work.
Here is the script located inside the clickable part :

local ServerStorage = game:GetService("ServerStorage")
local FireExt = ServerStorage:WaitForChild("FireCan")
local clickDetector = script.Parent:WaitForChild("ClickDetector")
local BackPack = game.Players.LocalPlayer.Backpack
function onClick()
	local clone = FireExt:Clone()
	clone.Parent = BackPack
	print("Added to inventory!")
end

clickDetector.MouseClick:Connect(onClick())

Also, is this a problem from my game or from roblox, since i see CoreGui

Thank you all for helping :heart:

Try this in a server script:

local ServerStorage = game:GetService("ServerStorage")
local FireExt = ServerStorage:WaitForChild("FireCan")
local clickDetector = script.Parent:WaitForChild("ClickDetector")

function onClick(player)
	local clone = FireExt:Clone()
	clone.Parent = player.Backpack
	print("Added to inventory!")
end

clickDetector.MouseClick:Connect(onClick)
1 Like

I don’t believe that’s got to do with the backpack, I’ve been getting the same error.

Yeah, its ever since the new Top Bar updates

The script works and in order to avoid creating a different topic for the same script, how can i make so the player gets only 1 fire tool ?
Edit : After some quick research i’ve found the solution and explanation. But thank you so much for helping :heart:

1 Like