Hi, I have a script that sets the walkspeed of the player when they enter the game depending on the team they are on however it doesn't seem to function and I can't identify the problem.
Here is the script:
plr = script.Parent function onSpawn(Char) if game.Players:FindFirstChild(Char.Name)~=nil then if plr.TeamColor==BrickColor.new("Really black") then Char.Humanoid.WalkSpeed = 0 end end game.Workspace.ChildAdded:connect(onSpawn)
For first, its better to detect when Player added and Character added.
And in your code have a deprecated function: :connect
, change it to :Connect
To detect when player and character added have a function for that:
game.Players.PlayerAdded:Connect(function(Player) print("Player", Player.Name, "Joined the game!") Player.CharacterAdded:Connect(function(Character) print("Character of", Player.Name, "Spawned!") end) end)
In your case, you only need to check team, then wait for Humanoid and set speed to 0 Fixed script:
game.Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) if Player.TeamColor == BrickColor.new("Really black") then Character:WaitForChild("Humanoid").WalkSpeed = 0 end end) end)
Hope it helped! :)