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

A :clone() can only be used once? How do I fix?

Asked by
lucas4114 607 Moderation Voter
9 years ago

So, I have a script to give a random weapon when player respawns, so... There are 5 weapons, I killed myself 5 times and the 6th time spawned with nothing and also noticed that each respawn I never ended up with a same weapon from before... So... I guess this means that when I use :clone() it only makes one clone then if that was destroyed it wouldn't make another one??.. Help?

AK47 = game.ServerStorage.AK47:Clone()
ACR = game.ServerStorage.ACR:Clone()
ASVal = game.ServerStorage.ASVal:Clone()
MP5 = game.ServerStorage.MP5:Clone()
Pistol = game.ServerStorage.Pistol:Clone()


game.Players.PlayerAdded:connect(function(plr) 
    plr.CharacterAdded:connect(function() 
        local Weapon = (math.random(5))
        if Weapon == 5 then
            AK47.Parent = plr:WaitForChild("Backpack")
        end
        if Weapon == 4 then
            ACR.Parent = plr:WaitForChild("Backpack")
        end
        if Weapon == 3 then
            ASVal.Parent = plr:WaitForChild("Backpack")
        end
        if Weapon == 2 then
            MP5.Parent = plr:WaitForChild("Backpack")
        end
        if Weapon == 1 then
            Pistol.Parent = plr:WaitForChild("Backpack")
        end
    end) 
end) 

1 answer

Log in to vote
0
Answered by 9 years ago

You are using Player added instead of the property onPlayerRespawn. Try this:

AK47 = game.ServerStorage.AK47:Clone()
ACR = game.ServerStorage.ACR:Clone()
ASVal = game.ServerStorage.ASVal:Clone()
MP5 = game.ServerStorage.MP5:Clone()
Pistol = game.ServerStorage.Pistol:Clone()



function onPlayerRespawn(property, player) -- the changed part
        local Weapon = (math.random(5))
        if Weapon == 5 then
            AK47.Parent = plr:WaitForChild("Backpack")
        end
        if Weapon == 4 then
            ACR.Parent = plr:WaitForChild("Backpack")
        end
        if Weapon == 3 then
            ASVal.Parent = plr:WaitForChild("Backpack")
        end
        if Weapon == 2 then
            MP5.Parent = plr:WaitForChild("Backpack")
        end
        if Weapon == 1 then
            Pistol.Parent = plr:WaitForChild("Backpack")
        end
    end)
0
It worked.. :D lucas4114 607 — 9y
0
Glad I could help :D jimborimbo 94 — 9y
Ad

Answer this question