Blocking slowdown speed not working

There is an issue with my blocking logic. The speedmanager is suppose to slow down the speed of the user while blocking… something is immediately reverting it back to speed 16 and not 5…

visual example : Watch 2024-03-21 23-32-30 | Streamable

this is the local part of the block

local isUserBlockingConnection = BridgeNet.ClientBridge("UserBlocking")
local isUserBlocking = false
local canBlockAgain = true
local blockCooldown = 1

local function startBlockCooldown()
	canBlockAgain = false
	wait(blockCooldown)
	canBlockAgain = true
end

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if gameProcessedEvent then return end
	if input.KeyCode == Enum.KeyCode.F and canBlockAgain then
		if not toolEquipped then return end
		isUserBlocking = true
		isUserBlockingConnection:Fire(isUserBlocking)
		Character:SetAttribute("IsBlocking", true)

		local humanoid = Character:FindFirstChildOfClass("Humanoid")
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, not isUserBlocking)

		local runningSound = Character.HumanoidRootPart:WaitForChild("Running", 10)
		runningSound.Volume = 0

		coroutine.wrap(startBlockCooldown)()
	elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
		handleAttack()
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.F then
		isUserBlocking = false
		isUserBlockingConnection:Fire(isUserBlocking)
		Character:SetAttribute("IsBlocking", false)

		local humanoid = Character:FindFirstChildOfClass("Humanoid")
		humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)

		local runningSound = Character.HumanoidRootPart:WaitForChild("Running", 10)
		runningSound.Volume = 1
	end
end)

speed manager looks like this here

local SpeedManager = {}

function SpeedManager:applySlow(character, slowFactor, duration)
	if not character then return end
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	if SpeedManager[humanoid] then
		SpeedManager[humanoid]["Duration"] = duration
		task.cancel(SpeedManager[humanoid]["Thread"])
	else
		local originalSpeed = humanoid.WalkSpeed
		local originalJumpHeight = humanoid.JumpHeight
		local originalJumpPower = humanoid.JumpPower
		local currentSpeedFactor = character:GetAttribute("CurrentSpeedFactor") or 1
		local newSpeedFactor = currentSpeedFactor * slowFactor

		if currentSpeedFactor == 1 then
			character:SetAttribute("CurrentSpeedFactor", newSpeedFactor)
			humanoid.WalkSpeed = originalSpeed * newSpeedFactor
			humanoid.JumpHeight = 0
			humanoid.JumpPower = 0
		end

		SpeedManager[humanoid] = {
			Factor = newSpeedFactor,
			Duration = duration,
			OriginalSpeed = originalSpeed,
			OriginalJumpHeight = originalJumpHeight,
			OriginalJumpPower = originalJumpPower,
		}
	end

	character:SetAttribute("IsStunned", true)

	local Thread = task.delay(duration, function()
		if SpeedManager[humanoid] then
			character:SetAttribute("CurrentSpeedFactor", 1)
			humanoid.WalkSpeed = SpeedManager[humanoid].OriginalSpeed
			humanoid.JumpHeight = SpeedManager[humanoid].OriginalJumpHeight
			humanoid.JumpPower = SpeedManager[humanoid].OriginalJumpPower
			SpeedManager[humanoid] = nil
		end
		character:SetAttribute("IsStunned", false)
	end)

	SpeedManager[humanoid]["Thread"] = Thread
end

function SpeedManager:ApplyEffect(character, effect)
	if not character then return end
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end

	local characterName = character.Name
	print("Applying effect to character:", characterName)

	if effect == "block" then
		if not character:GetAttribute("OriginalWalkSpeed") then
			character:SetAttribute("OriginalWalkSpeed", humanoid.WalkSpeed)
			character:SetAttribute("OriginalJumpHeight", humanoid.JumpHeight)
		end
		humanoid.WalkSpeed = 5
		humanoid.JumpHeight = 0
		print(humanoid.WalkSpeed)
	elseif effect == "normal" then
		humanoid.WalkSpeed = character:GetAttribute("OriginalWalkSpeed") or 16
		humanoid.JumpHeight = character:GetAttribute("OriginalJumpHeight") or 7.2
		character:SetAttribute("OriginalWalkSpeed", nil)
		character:SetAttribute("OriginalJumpHeight", nil)
	end
end

return SpeedManager

Can you reply with the script where you’re actually calling the SpeedManager module? Need a bit more to work with… thanks

1 Like

The slow isn’t being called in the script.

1 Like

I forgot to provide the module block handler my bad…

local BlockHandler = {}

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BridgeNet = require(ReplicatedStorage.Modules.BridgeNet2)
local SpeedManager = require(script.Parent.SpeedManager)
local Animations = ReplicatedStorage:WaitForChild("Animations")
local blockAnimation = Animations:WaitForChild("Fist"):WaitForChild("Blocking")

local isUserBlockingConnection = BridgeNet.ServerBridge("UserBlocking")

local playerAnimationTracks = {}

isUserBlockingConnection:Connect(function(player, isBlocking)
	local character = player.Character or player.CharacterAdded:Wait()

	local isDashing = character:GetAttribute("IsDashing")
	local isPunching = character:GetAttribute("IsPunching")
	if isDashing or isPunching then
		return
	end

	character:SetAttribute("IsBlocking", isBlocking)

	if isBlocking then
		character:SetAttribute("PerfectBlock", true)
		delay(0.1, function()
			if character:GetAttribute("IsBlocking") then
				character:SetAttribute("PerfectBlock", false)
			end
		end)

		character:SetAttribute("BlockCount", 0)
	else
		character:SetAttribute("PerfectBlock", false)
		character:SetAttribute("BlockCount", nil)
	end

	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end
	local animator = humanoid:FindFirstChildOfClass("Animator") or Instance.new("Animator", humanoid)

	if not playerAnimationTracks[player] then
		playerAnimationTracks[player] = animator:LoadAnimation(blockAnimation)
	end

	local animationTrack = playerAnimationTracks[player]
	if isBlocking then
		animationTrack:Play()
		SpeedManager:ApplyEffect(character, "block")
	else
		animationTrack:Stop()
		SpeedManager:ApplyEffect(character, "normal")
	end
end)


game.Players.PlayerRemoving:Connect(function(player)
	playerAnimationTracks[player] = nil
end)

return BlockHandler

Why make a whole module just for a walkspeed change? Why dont you just do it in the lines?