SS = game.ServerStorage plr = game.Players:GetChildren() function SM() if true then for i = 1, #plr do SS.SWeps.Sword:clone().Parent = plr[i].Backpack print'hi' end else print'?' end end
When I run the function the sword
doesn't get given to the player?
SWeps
is a model where i put all the weapons and Sword
is the sword.
In line 5, you're not defining what true has to be. You're basically saying if true = true.
A more efficient, and better working code would be:
for i, player in ipairs(game.Players:GetChildren()) do SS.SWeps.Sword:clone().Parent = player.Backpack end
Also, since the script is accessing server storage, make sure this isn't a local script.
As what teamkilled said, using
if true then
is useless.
Try this:
function SM() for _, player in pairs(game:GetService('Players'):GetPlayers()) do Spawn(function() player:WaitForChild('Backpack') SS.SWeps.Sword:clone().Parent = player.Backpack end) end end
The breakdown of this:
The for loop iterates through the players.
The Spawn function runs whatever is in the parenthesis (a function) in another thread, thereby allowing the script to continue while another thread is dealing with the individual player.
The new thread then yields until player.Backpack is found.
The sword is cloned into the backpack.
Please remember to upvote if this helps. It helps me.