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.
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
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?
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)
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.
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
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.
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…