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

Trying to clone a tool, why won't it work?

So I'm trying to clone a tool from ReplicatedStorage to the players Backpack but it isn't working for some reason. Her'es the script:

script.Parent.ClickDetector.MouseClick:connect(function()
	local clone = game.ReplicatedStorage.Pyro:Clone()
	local player = game.Players.LocalPlayer
	clone.Parent = player.Backpack
end)

I've also tried this:

local player = game.Players.LocalPlayer
local clone = game.ReplicatedStorage.Pyro:Clone()

script.Parent.ClickDetector.MouseClick:connect(function()
	clone.Parent = player.Backpack
end)

But none work. Been trying to get this to work since Yesterday, I asked on the ROBLOX forums but no one was giving me a correct solution.

This is in a local script inside a part with a ClickDetector

2 comments

0

Hint: use a server script

0

I don't think a local script will work if it's in any game service other than the ones that get put into the players e.g. ScreenGui StarterPack or StarterPlayerScripts... It needs to be a normal script and a local script in screengui that connects with that one to make it work when it's clicked

2 answers

✓ Accepted answer

Here is how I would have done it;

First off, your script is most likely in a game service that will not get put into a player, what do I mean by that? By that I mean, if you put a local script in Workspace, workspace has no Local player which means the local script cannot find the player to clone the tool into.

I have changed the script some what but here it is, it works for me.

It is a Local Script in ScreenGui and the part with the click detector is called "AToolGiver" and is stored in Workspace.

local player = game.Players.LocalPlayer
local cd = game.Workspace:WaitForChild("AToolGiver")
local copy = game.ReplicatedStorage:WaitForChild("Pyro")

cd.ClickDetector.MouseClick:connect(function()
	copy:Clone().Parent = player.Backpack
end)

2 comments

0

Thanks. I'm actually trying to do this with a Gui now. Basically what I'm trying to do is clone the Gui from ServerStorage to PlayerGui, it will work for this too right?

0

Covered that! lol

are you using a localscript? If you are not using a localscript LocalPlayer don't work!

1 comment

0

Yes, it's in a LocalScript

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