Help with slow system

  1. What do you want to achieve?
    I want to achieve a reliable humanoid walkspeed slow system where the longest/largest slow overrides the old one if there is one and if it’s shorter in duration.

  2. What is the issue?
    The issue is for example, a humanoid gets slowed for 3 seconds, but they get slowed for 10 seconds while slowed for 3 seconds, their walkspeed will return to 16 after those 3 seconds and the longer stun will be scrapped.

  3. What solutions have you tried so far?
    Tried some hotfixes with CollectionService, NumberValues and while loops but none of them are reliable.

local character = script.Parent

local collectionService = game:GetService("CollectionService")
local humanoid = character:WaitForChild("Humanoid")

local bindableEvent = Instance.new("BindableEvent")
bindableEvent.Name = "BindableEvent"
bindableEvent.Parent = character 

local eventFunctions = {
	["UpdateState"] = function(...)
		local info = ...;
		local state = info.State
		
		local TableArguments = info.TableArguments
		if state == "isSlowed" then
			local SlowAmount = TableArguments.SlowAmount
			humanoid.WalkSpeed = SlowAmount
			local Duration = TableArguments.Duration	
            --dont know what to put here instead of delay
			delay(Duration,function()
				humanoid.WalkSpeed = 16 
			end)
		end
	end,
}
bindableEvent.Event:Connect(function(Keyword,TableArguents)
	eventFunctions[Keyword](TableArguents)
end)

I can provide the rest of the code such as how it gets to the bindable event if requested but did not do it here to not flood. Any help is appreciated.

I didn’t quite understand what you meant, but maybe you are searching for this:

have you tried to set a variable to the time left, or to the tick, and then check if (stunChanged) duration is more than it the old?

i’ll be here to help you.

Example: Humanoid gets slowed by an ability for 5 seconds, having their walkspeed as let’s say 5 for the time being. Then let’s say the humanoid gets slowed again, in between those 5 seconds, for 15 seconds. Using delay will un-slow the humanoid after 5 seconds regardless of that 15 second stun running. Meaning the longer stun will be scrapped. And no I haven’t yet, will try now one moment.

tell me when u’re done

so let’s say that you add 15 seconds to the remaining time?

sorry if i dont understand very well

Use a variable that changes everytime a new stun is added, then when you need to “unslow” the humanoid, check if the variable is the same as the beginning. Will show you the system I mean then you can implement it in your own code:

local count = 1;
local function slow(amount)
   humanoid.WalkSpeed = 4;
   count += 1;
   local currentCount = count;
   task.wait(amount);
   if count == currentCount then
      humanoid.WalkSpeed = 16;
   end;
end;
slow();

The current time thing using os.clock() worked, thank you

1 Like

Solved, all good, thanks for replying though.

1 Like