Yep, that’s what I made it do. Change the number in the task.wait(0.5)
to something like 0.2 to do it more frequently.
Oh I just realized, I am so sorry!
No worries! Let me know if there are any more issues.
It works like a charm! I’ve tried using it in any way possible to try and trick the system but no bugs have seemed to surface! I’ll consider this issue sealed, thank you so much for the time and for making this possible once more!
Just realised I literally overcomplicated everything massively, we could’ve just done a while loop i am an idiot
while humanoid.MoveDirection.Magnitude > 0 and humanoid.FloorMaterial ~= Enum.Material.Air do
print(humanoid.FloorMaterial)
print("Person is running")
VFXController.Action("Run", true)
task.wait(0.2)
end
Regardless, thank you for your patience, and I wish you the best of luck on your game!
Hey you’re far from an idiot. I’ll try that! If it works I’ll move the solution to there!
I have spoken too soon… once more.
I noticed that if I run constantly, it starts to lag until I stop running. What do I do?..
You could use HumanoidRootPart.Velocity
to check for speed.
Also on this line it appears to be that you’re comparing numbers directly.
else if speed == 0 then
This is generally not a recommended practice because numbers will rarely ever be equal to each other.
Try doing this instead:
else if speed < 0.1 then
Though, you might want to replace speed
with humanoid.RootPart.Velocity.Magnitude
instead.
This is effectively the same as Humanoid.MoveDirection.Magnitude
.
Does this happen with the RunService loop as well?
I’m not sure, how do I tell if that’s the case?
Hi, so after observing the conversations on this topic or your issue, there are several or more steps to determine whether you are moving or in different humanoid states. You could use the magnitude of the Velocity in order to determine if you are moving or in motion in any direction.
For example:
local plr : (Player) = (game:GetService("Players").LocalPlayer)
local char : (Model) = (plr.Character or plr.CharacterAdded:Wait())
local hum = (char:WaitForChild("Humanoid"))
while (task.wait()) do
if (hum.PrimaryPart.AssemblyLinearVelocity.Magnitude) > 0 then
print("moving or in motion!", hum.PrimaryPart.AssemblyLinearVelocity.Magnitude)
else
print("not moving!")
end
end;
But, from my perspective, your code should have worked properly. The thing that might be causing those is loop management or conditional statements (Those might be the things that are causing the lags).
I have no doubt that using MoveDirection or determining the velocity will work it could’ve been loop management or conditional statements
This won’t work because they could be in the air as well, thus triggering this as well.
Furthermore, the problem is specifically that the loop lags when they move for prolonged periods of time.
You put the RunService loop that I provided before instead of the while loop.
My instincts tell me that it’s not because of this but because of something else. You may have a memory leak due to unneeded connections.
Shoot. I have no idea how I’m going to resolve that…
I’m not the best at scripting, as a matter of fact, my friend told me he will revise all of my scripts because he’s concerned about memory leaks. Yikes…
If you want to prevent Memory Leaks, you can do the following
- Avoid having loops inside loops, e.g.
while true do
game:GetService("RunService").RenderStepped:Connect(function()
print("bla bla bla")
end)
end
You don’t need these two loops or connections inside each other. When you see it, you want to either remove one of them or to move the connection that’s inside to the outside so that it runs alongside the other connection
- Disconnect connections that only need to work once in a given scenario like so:
local clickConnection
clickConnection = button.MouseButton1Click:Connect(function()
print("yes")
clickConnection:Disconnect()
end)
This’ll save on memory since if you have the connection running permanently, it’ll be listening forever.
There are other things you can do too, like checking out the Micro-Profiler to accurately identify where lag is coming from. Hope this helped!
Alright, i’ll check those. Though do you think it’s causing the problem?
P.S I have never used a microprofiler, I need to learn how to use it LOL
It probably is. Try disabling the script with the loop - does that improve anything?
Try with and without moving - is there a difference?
So far we know that
script enabled
- while moving: lags after moving a lot
- while not moving: ?
script disabled
- while moving: ?
- while not moving: ?
See if you can complete the table: could give us an insight if it’s caused by this.
Roblox has an inbuilt micro-profiler. You can read a bit more here: Using MicroProfiler | Documentation - Roblox Creator Hub
Though, it can get a bit advanced.
So to change that a bit:
Script Enabled
While Moving: Lags
While Not Moving: Lags Stops until person moves again for a period of time
The microprofiler goes INSANE after running.
I think it even broke my PowerUps script because at the end they weren’t working!