function CalibrateMovement(actionName, inputState, _inputObject)
if actionName == Action_RUN then
if inputState == Enum.UserInputState.Begin then
print("Running")
task.spawn(RunThread)
task.cancel(WalkThread)
elseif inputState == Enum.UserInputState.End then
print("Walking")
task.spawn(WalkThread)
task.cancel(RunThread)
end
end
end
The Walkthread lowers the player’s walk speed till it hits the desired amount and the RunThread is the same thing but reversed.
However, if you could tell just by looking at these, that the script wouldn’t let me cancel either thread after spawning it, causing me to get this error invalid argument #1 to 'cancel' (thread expected, got function)
How can I be able to cancel the walk/run thread? What am I doing wrong?
This is my first time messing with canceling or spawning threads, so please correct me if I’m using it wrong.
But the Walk and Run threads look like this.
local RunThread = function()
repeat
wait()
Humanoid.WalkSpeed += SpeedIncerments
print("+",Humanoid.WalkSpeed)
until Humanoid.WalkSpeed >= MaxRunSpeed
Humanoid.WalkSpeed = MaxRunSpeed
end
local WalkThread = function()
repeat
wait()
Humanoid.WalkSpeed -= SpeedIncerments * 1.5
print("-",Humanoid.WalkSpeed)
until Humanoid.WalkSpeed >= MinWalkSpeed
Humanoid.WalkSpeed = MinWalkSpeed
end
Well, I’ve tried that before. However, after press V “Which starts the run thread” it works fine, but, when you let go of V the walk thread does work as intended, as it doesn’t lower the walk speed back down
No, you have to redefine them becuase a closed thread cannot be run again, so if you use a close thread in task.spawn or coroutine.resume it will error.
Redefining the threads will replace the closed one with its resumable state again.