Reseting walkspeed doesnt work (For a stun)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

a stun so every time player gets hit they cant move/jump for a period of time, the script is set in a module and is called from client side.

Observe how the walk speed changes on the right side panel in the video

and i just realized u can walk out of the stun when u press the D key i don’t know why or how this is happening i have no conflicting scripts i checked

  1. What is the issue?

for some reason when i don’t move and get hit it works fine, but if I’m moving and i get hit i can still move almost like the repeat function is going off

  1. What solutions have you tried so far?

nothing to try


local Controller = {}

local activeWalkCoroutine
local activeJumpCoroutine

Controller.State = function(Humanoid, Duration)

	local Character = Humanoid.Parent

	if activeWalkCoroutine and coroutine.status(activeWalkCoroutine) ~= "dead" then
		coroutine.close(activeWalkCoroutine)
	end
	if activeJumpCoroutine and coroutine.status(activeJumpCoroutine) ~= "dead" then
		coroutine.close(activeJumpCoroutine)
	end
	
	Humanoid.JumpHeight = 0

	repeat 
		task.wait()
		Humanoid.WalkSpeed = 0
		Duration -= 1 
	until Duration <= 0 

	activeWalkCoroutine = coroutine.create(function()
		task.wait(1)
		Humanoid.WalkSpeed = 16
	end)
	coroutine.resume(activeWalkCoroutine)

	activeJumpCoroutine = coroutine.create(function()
		task.wait(0.25)
		Humanoid.JumpHeight = 7.2
	end)
	coroutine.resume(activeJumpCoroutine)

end

return Controller


1 Like

Dunno about you but it seems like the duration goes down immediately because you didn’t put anything in the task.wait()

1 Like

Looks like it’s the Duration should be holding the repeat back vs the task.wait()

Are you sure Duration is being passed with a value > 1?

repeat
    task.wait()
    Humanoid.WalkSpeed = 0
    print("Duration is currently: " .. Duration)
    Duration -= 1
until Duration <= 0
1 Like

Your duration is depleting instantly because you left the task.wait() empty. This means each task.wait() will only yield for a single frame. So, at 60 FPS, if Duration is originally set to 60, it will reach 0 in a single second. I recommend setting Duration to however many seconds you want it to yield (e.g set Duration to 1 if you want them to be stunned for 1 full second) and then change the task.wait() to task.wait(1)

Ok so i changed it to , because the duration is 0.8s :

	repeat 
		task.wait(0.1)
		Humanoid.WalkSpeed = 0
		Duration -= 0.1
	until Duration <= 0 

and now it sorta works more often but you can still “slip out”.

Never mind guys i fixed it i was actually doing it from there server and there is server lag so we good thanks tho y’all

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.