Trying to make char slow while in combat mode

Each time you hit, or do a M1 i want to slow the character for like 1 second, but if i just make it like:

Humanoid.WalkSpeed = 4
task.wait(1)
Humanoid.WalkSpeed = 16

That wouldnt work, i want to reset the countdown from 1 to 0 each time you click.
This is the code i have for now:

if info.Key == Enum.UserInputType.MouseButton1 then
		if sf.SetCooldown({plr = player, ability = "Punch", check = true}) then return end
		if collectionService:HasTag(character, "attackEnd") then return end
		sf.SetCooldown({plr = player, ability = "Punch", dura = .3})
		
		Attacking = true
		task.delay(1,function()
			Attacking = false
		end)
		
		if Combo.Value >= 5 then
			collectionService:AddTag(character, "attackEnd")
			Combo.Value = 0
			--pause after full combo--
			task.delay(1.5, function()
				collectionService:RemoveTag(character, "attackEnd")
			end)
			return
		end

		if tick()-Lastm1.Value > 2 then
			Combo.Value = 0
		end

		Lastm1.Value = tick()

		Combo.Value += 1
		print(Combo.Value)

		--play animation--
		Engine:FireClient(player, "LoadAnim", {Animation = repStorage.Animations:FindFirstChild("Combo"..Combo.Value), human = human})

	end

In this part:

Attacking = true
		task.delay(1,function()
			Attacking = false
		end)

I wanted to try and check if attacking is true, if it is slow the character for one second, but i cant see how i can do that

1 Like

Are you trying to change the walkspeed in one second without yielding the script?

You can try using TweenService:

local TS = game:GetService("TweenService")

Humanoid.WalkSpeed = 12
TS:Create(Humanoid,TweenInfo.new(1,Enum.EasingStyle.Exponential,Enum.EasingDirection.Out),{WalkSpeed = 16}):Play()
--Set walkspeed to 12, then gradually increase it.

You can do this:

coroutine.wrap(function()
	for t = 1, 10 do -- 1 second
task.wait(0.1)
if Attacking = true then
Humanoid.WalkSpeed = 4
else
Humanoid.WalkSpeed = 16
 break end
end)()

Doesn’t this yield the script?

--Variables--
local Attacking = false
local Attacks = 0

--code--

Attacks += 1
Attacking = true

human.WalkSpeed = 5
		
local oldFires = Attacks
task.delay(1, function()
	if Attacks == oldFires then
		Attacking = false
		human.WalkSpeed = 16
	end
end)```
this is the way i did it and it works

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