Answered by
8 years ago Edited 8 years ago
Please use code block in the future
Your problem is most likely that you are attempting to index the LocalPlayer
from a server script.
Try parenting this code into StarterPack from a LocalScript and it should work.
But note - it will make duplicate swords so you should probably add a check. And localscripts can't access ServerStorage so would need to put the tool in ReplicatedStorage
01 | local sword = game.ReplicatedStorage [ "Linked Sword" ] ; |
02 | local plr = game.Players.LocalPlayer; |
06 | if not plr.Backpack:FindFirstChild(sword.Name) then |
07 | sword:Clone().Parent = plr.Backpack; |
Alternatively, if you want the whole server to recieve swords at the same time, you can use a generic for loop and iterate through the players from a script in Workspace.
01 | local sword = game.ServerStorage [ "Linked Sword" ] ; |
05 | for _,v in next ,game.Players:GetPlayers() do |
06 | if not v.Backpack:FindFirstChild(sword.Name) then |
07 | sword:Clone().Parent = v.Backpack; |