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

Why isn't this script working?

Asked by 8 years ago

So I was making a script to insert a tool into a player's startergear when they join. Here's the script:

function PlayerAdded(player)
if player.Name == workspace.ToolValues.Tool.Value then
game.ServerStorage.Tool:Clone().Parent = game.Players[player.Name].StarterGear
end
end
game.Players.PlayerAdded:connect(PlayerAdded)

When I try this, it says "StarterGear is not a valid member of Player" Any thoughts as to why this isn't working?

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

It is likely that you are trying to gain access to StarterGear before it is created. Try adding a WaitForChild method call on line 3:

game.ServerStorage.Tool:Clone().Parent = game.Players[player.Name]:WaitForChild("StarterGear")
Ad

Answer this question