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

How to change a players movement speed?

Asked by
sheepposu 561 Moderation Voter
5 years ago

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)

2 answers

Log in to vote
0
Answered by 5 years ago

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)
0
Oh, I see thx sheepposu 561 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

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
1
That way there is much simpler and works every time Protogen_Dev 268 — 5y

Answer this question