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

Player Moving Function?

Asked by
dyler3 1510 Moderation Voter
10 years ago

I've been experimenting lately, and I can't figure out a function(s) that fires when player moves. I've tried using the Changed, and ChangedState functions, neither of which have worked for me. If there is a way to use these, or if there's another way then please help me out.

This is an example of something I've tried:

Player=game.Players.LocalPlayer ---Yes I know this requires a LocalScript---
Player.Character.Torso.Changed:connect(function(Property)
    if Property="Position" then
        print("Yay")
    end
end)

Anyways, if anyone could help me out, thanks in advance :P

1 answer

Log in to vote
1
Answered by 10 years ago

You can use the Runningevent inside Player.Character.Humanoid. This is fired when the player begins or ends moving.

Example:

Player = game.Players.LocalPlayer
repeat wait() until Player.Character -- This waits for the character to spawn in

Player.Character:WaitForChild("Humanoid").Running:connect(speed)
    --You have to include the 'speed' parameter to check if they are starting to run rather than stopping
    if speed > 0 then
        print("Player has begun to run!")
    else
        print("Player has stopped running!")
    end
end)
0
Thank you! Got my script to work now :D dyler3 1510 — 10y
Ad

Answer this question