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 10 years ago

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

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

Help?

5 answers

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

You have to set the parent;

game.Lighting.Sword:Clone().Parent = backpack
Ad
Log in to vote
1
Answered by 10 years ago
local backpack = game.Players.LocalPlayer.Backpack
script.Parent.Touched:connect(function()
    modelcopy=game.Lighting.Sword:Clone()

modelcopy.Parent=backpack
end)
0
One error you had is you said "BackPack" but it needs to be "Backpack" Tempestatem 884 — 10y
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 — 10y
Log in to vote
1
Answered by 10 years ago
local backpack = game:service("Players").LocalPlayer.Backpack
--script.Parent.Touched:connect(function()
game:service("Lighting"):FindFirstChild("Sword"):Clone().Parent=backpack
--end)
1
Hmm, I don't know why but, none of these work! Sorry. Grenaderade 525 — 10y
Log in to vote
1
Answered by 10 years ago

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

local sword = game.Lighting.Sword
script.Parent.Touched:connect(function(h)
    local player = game.Players:GetPlayerFromCharacter(h.Parent) -- find the player from the character

    if (player) then
        -- a player touched it

        local clone = sword:Clone()
        clone.Parent = player.Backpack -- parent the clone to the player's backpack
    end
end)

Log in to vote
1
Answered by 10 years ago
script.Parent.Touched:connect(function(p)
    p = game.Players:GetPlayerFromCharacter(p.Parent)
    if p then
        game.Lighting.Sword:Clone().Parent = p.Backpack
    end
end)

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 — 10y
0
I did put it in a localscript. Grenaderade 525 — 10y
0
Oh.. Well...... Are you putting it in a brick? fireboltofdeath 635 — 10y
0
Oh and..... Do you have a object named "Sword"? It has to have capital. fireboltofdeath 635 — 10y
0
Fixed it. fireboltofdeath 635 — 10y

Answer this question