So I have a script that I made and put into ServerScriptService. It is suppoed to first, create the variable "PlrBlk". Next it is supposed to use the name of the play stored in PlrBlk and find the player in the workspace. That is asigned to the variable "plr". The variable humanoid represents "Humanoid", found inside plr. Back to line 3. The error is that the value of plr is nil and I can't figure out why. Thanks in Advance
game.Players.PlayerAdded:Connect(function(player) local PlrBlk = player.Name local plr = workspace:FindFirstChild(PlrBlk) local humanoid = plr:FindFirstChild("Humanoid") humanoid.Walkspeed = 0 end)
you could just index the Character
property of the player object instead, though you'd need to listen for the CharacterAdded
event since the character probably didnt load yet once PlayerAdded
was fired. then use :WaitForChild()
on the humanoid, since it also might have not loaded yet and the property is called WalkSpeed
not Walkspeed
. also dont use :FindFirstChild()
just to directly index the object like what you'd use with the .
operator; use it to check if a object exists or not.
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoid = character:WaitForChild("Humanoid") humanoid.WalkSpeed = 0 end) end)
The best idea is just out a local script inside of StarterCharacterScripts that says this.
repeat wait() until script.Parent.Humanoid ~= nil script.Parent.Humanoid.WalkSpeed = 20