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

Why won't this clone?

Asked by 11 years ago

I made this really simple script, but it's not working.

1local backpack = game.Players.LocalPlayer.BackPack
2script.Parent.Touched:connect(function()
3    game.Lighting.Sword:Clone(backpack)
4end)

Help?

5 answers

Log in to vote
1
Answered by
hiccup111 231 Moderation Voter
11 years ago

You have to set the parent;

1game.Lighting.Sword:Clone().Parent = backpack
Ad
Log in to vote
1
Answered by 11 years ago
1local backpack = game.Players.LocalPlayer.Backpack
2script.Parent.Touched:connect(function()
3    modelcopy=game.Lighting.Sword:Clone()
4 
5modelcopy.Parent=backpack
6end)
0
One error you had is you said "BackPack" but it needs to be "Backpack" Tempestatem 884 — 11y
1
Neither of yours work, I don't know what's going on! Wait, is it because it doesn't work in test? Grenaderade 525 — 11y
Log in to vote
1
Answered by 11 years ago
1local backpack = game:service("Players").LocalPlayer.Backpack
2--script.Parent.Touched:connect(function()
3game:service("Lighting"):FindFirstChild("Sword"):Clone().Parent=backpack
4--end)
1
Hmm, I don't know why but, none of these work! Sorry. Grenaderade 525 — 11y
Log in to vote
1
Answered by 11 years ago

Try this. Make sure you put it in the part that gives the sword.

01local sword = game.Lighting.Sword
02script.Parent.Touched:connect(function(h)
03    local player = game.Players:GetPlayerFromCharacter(h.Parent) -- find the player from the character
04 
05    if (player) then
06        -- a player touched it
07 
08        local clone = sword:Clone()
09        clone.Parent = player.Backpack -- parent the clone to the player's backpack
10    end
11end)
Log in to vote
1
Answered by 11 years ago
1script.Parent.Touched:connect(function(p)
2    p = game.Players:GetPlayerFromCharacter(p.Parent)
3    if p then
4        game.Lighting.Sword:Clone().Parent = p.Backpack
5    end
6end)

There you go!

0
Put this in Local Script. That's why none of these work. You didn't put it on Local Script fireboltofdeath 635 — 11y
0
I did put it in a localscript. Grenaderade 525 — 11y
0
Oh.. Well...... Are you putting it in a brick? fireboltofdeath 635 — 11y
0
Oh and..... Do you have a object named "Sword"? It has to have capital. fireboltofdeath 635 — 11y
0
Fixed it. fireboltofdeath 635 — 11y

Answer this question