Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago
Edited 8 years ago

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

0
Hint: use a server script LightModed 81 — 8y
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 sodaghost1 34 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

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)
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? xJoshRyan 23 — 8y
0
Covered that! lol sodaghost1 34 — 8y
Ad
Log in to vote
0
Answered by
Filipalla 504 Moderation Voter
8 years ago

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

0
Yes, it's in a LocalScript xJoshRyan 23 — 8y

Answer this question