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

How would I make this give all players a random sword?

I'm trying to finish my game. However, there is an issue that occurs. The script gives only ONE player a sword, instead of everyone in the server.

Swords = game.ReplicatedStorage.Swords:GetChildren()
--Select a random sword
selected = Swords[math.random(1,#Swords)]
selected:Clone().Parent = game.Players.LocalPlayer.Backpack

1 answer

✓ Accepted answer
for i,v in pairs (game.Players:GetPlayers()) do
Swords = game.ReplicatedStorage.Swords:GetChildren()
--Select a random sword
selected = Swords[math.random(1,#Swords)]
selected:Clone().Parent = v.Backpack
end

I used a pairs loop to get all the players in Players and ran the function to each one of them. This should only be ran once though, so it'd be best in a server script. (not a localscript)

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