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

How do I detect when a player walks?

Asked by 6 years ago

I am making a minigame. In one level the player must stay still. What is an easy way to detect when a player walks and detect what player walked. Can you link a wiki page?

2 answers

Log in to vote
0
Answered by
Tomstah 401 Moderation Voter
6 years ago

The easiest way to do this is with the Running event of the humanoid.

It'll look something like this:

local MovingCharacter = function(speed)
    if speed > 2 then --This makes it so they're not just moving from something else or by accident.
        --Code
    end 
end

workspace:FindFirstChild(--[[Name of the player]]--).Humanoid.Running:Connect(MovingCharacter)

What the code is doing is it detects if the characters running. Then to check if the character is just being moved or if it's moving at full speed. Just a tiny threshold.

Ad
Log in to vote
0
Answered by 6 years ago

Tomstah is correct, but I just felt that there was a more efficient way of doing it when checking players.

local MovingCharacter = function(speed)
    if speed > 2 then --This makes it so they're not just moving from something else or by accident.
        --Code
    end 
end

for _, player in pairs (game.Players:GetPlayers()) do
workspace:FindFirstChild(player).Humanoid.Running:Connect(MovingCharacter)
end

Answer this question