Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I move the cloned tool to the player's backpack ?

I want to make my own giver, I think I've done the basics (I tested it out a slight bit different way to spawn a car, worked), but I'm struggling to get the tool to the player's Backpack who cloned it.The script is a LocalScript

Here's what I've done:

local Button = script.Parent
local Flashlight = game.ServerStorage.NATMFlashlight
local Inventory = game.Players.LocalPlayer

function OnClicked()
	CopyBoy = Flashlight:Clone()
	CopyBoy.Parent =  Inventory.Backpack
end

Button.ClickDetector:connect(OnClicked)

2 comments

0

Local Scripts cannot access the ServerStorage. Only regular scripts can do that. Also, a Local Script cannot function in the Workspace. I will put the correct code below.

0

Thanks !

1 answer

✓ Accepted answer

"ClickDetector" is not an event. The event that fires when it is clicked is "MouseClick", and must be handled by a server script.

Put this code in a Script (not a LocalScript) inside the "Button"

local Button = script.Parent
local Flashlight = game.ServerStorage.NATMFlashlight

function OnClicked(Inventory) -- The player that clicked is a parameter to the function.
	CopyBoy = Flashlight:Clone()
	CopyBoy.Parent =  Inventory.Backpack
end

Button.ClickDetector.MouseClick:Connect(OnClicked)

This discussion is preserved as it was. New answers, comments, and votes are closed.