Is there a better way to check if a person is running or not?

Ah, my bad (i forgot it was a bindable not a remote). This makes sense, and is a good use of bindableevents.

Also, the reason why the script restarts is because it is in StarterCharacterScripts as you say. If you don’t want it to reset, you can just move it to StarterPlayerScripts and it won’t reset.

Single-Script Architectures are more favoured over multi-script architectures because it is an easier way to lay out and structure code. The former relies heavily on ModuleScripts with few scripts and localscripts, whereas the latter relies on more localscripts and scripts, and few modulescripts. Single-Script Architectures are great for OOP (a recommended practice to organise code), in case you were wondering. Sorry for the detour, but compiling into 1 script is a good way to organise code.

The function looks great and should work when put into a loop or standalone, repeating connection.

2 Likes

Okay! In that case, do you think I should merge both scripts into one? Or should I leave it as is considering they’re already developed?

As for the function, do I just do a RenderStepped to it then?

1 Like

I wouldn’t worry about merging the scripts, but it shouldn’t be too hard if you wanted to. Personally, I would have a moduleScript that handles VFX and can be called in local scripts, etc.
For the function, yeah a RenderStepped connection would be good :+1:

1 Like
local function onRunning(speed)
    game:GetService("RunService").RenderStepped:Connect(function()
    if humanoid.MoveDirection.Magnitude > 0 and humanoid.FloorMaterial then
        print("Person is running")
        Event:Fire("Run", true)
    else
        print("Person stopped or in air")
        Event:Fire("Idle", false)
        end
    end)
end

Like this? (I never used RenderStepped, Heartbeat or anything related to RunService, sorry if this seems like a silly question)

Also, what’s the purpose of RenderStepped in this context?

1 Like

Close. You want to move the RenderStepped connection outside the function.

game:GetService("RunService").RenderStepped:Connect(onRunning)

I would also recommend removing the speed parameter since you aren’t using it.

2 Likes

You can use Humanoid:GetPropretyChangedSignal("MoveDirection") to see if a player is moving

2 Likes


Should I move humanoid.Running:Connect(onRunning) inside the RenderStepped function?

1 Like

You don’t even need to constently check the move direction i think it’s more optimized

1 Like

As a matter of fact I did ask what’s the use behind it. Though, I’m open for anything! At the moment it’s a little confusing how things are going

1 Like

Actually, RenderStepped isn’t really needed here. @faze_paspro is completely right because this Humanoid:GetPropretyChangedSignal("MoveDirection") is far more efficient and less laggy.
You can simply just do:

Humanoid:GetPropretyChangedSignal("MoveDirection"):Connect(function()
    if humanoid.MoveDirection.Magnitude > 0 and humanoid.FloorMaterial then
        print("Person is running")
        Event:Fire("Run", true)
    else
        print("Person stopped or in air")
        Event:Fire("Idle", false)
    end
end)
1 Like

Alright! Got it! Though I’d assume I have to move the last line inside that function because it doesn’t recognize it. It says unknown global.


(Referring to humanoid.Running:Connect(onRunning)

RenderStepped is used for things like the camera and character manipulation. I would’ve thought that it was more useful here but the other connection is more useful and way more efficient as if your player is AFK and not moving, then there the RS connection will continue to play, lagging the game.

1 Like

If i’m correct RenderStepeed is used for camera purposes in this case you should probably use RunService.Heartbeat instead wich the same but it’s used to run code every frame (I myself don’t really know why we should use renderstepped for camera because it also runs code every frame but that’s what i know), but you should avoid too many constent checking

1 Like

You don’t need the last line since the connection above automatically runs when they move. You never declared onRunning anywhere either.
By the way, it’s GetPropertyChangedSignal, not GetPropretyChangedSignal. Small typo.

1 Like

Yeah, it’s GetPropertyChangedSignal, you mispelled part of it.

Humanoid:GetPropertyChangedSignal("MoveDirection")

Oh I just realized! My bad! (30char)

1 Like

Also why you have this humanoid.FloorMaterial ?

So, this happens now, assuming this is how it’s supposed to go.

The reason why is that I need to make it detect if a person is doing another action like Jumping, FreeFalling, Climbing, Swimming, etc so it doesn’t trigger the effects. Though, it’s still not working…

1 Like