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

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

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

✓ Accepted answer

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)

2 comments

0

It worked.. :D

0

Glad I could help :D

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