Walkspeed updated function, if statement problem

local pressing_runningbutton = false
local no_double_tap = true
local sprinting = false
local speedremote = replicatedstorage.Basics.WalkSpeedCheck
local running = player.Character.Humanoid:LoadAnimation(script.Running)

local function updateSpeed()
    if pressing_runningbutton and chr:GetAttribute("Stun") == false then
        human.WalkSpeed = 25
        human.JumpPower = 30
        sprinting = true
        if human.Health > 1 then
            running:Play()
        end
        human.AutoRotate = true
        speedremote:FireServer(pressing_runningbutton)
    else
        running:Stop()
        speedremote:FireServer(pressing_runningbutton)
        sprinting = false
        if chr:GetAttribute("Stun") == true or player.Character:WaitForChild("Values").NormalVals.Ragdoll.Value == true or player.Character:GetAttribute("GettingBeatdown") == true then
            player.Character.Humanoid.WalkSpeed = 0
            player.Character.Humanoid.JumpPower = 0
            player.Character.Humanoid.AutoRotate = false
        elseif chr:GetAttribute("Attacking") == true then
            human.WalkSpeed = walk_attack.Value
            human.JumpPower = jump_attack.Value
            human.AutoRotate = true
        elseif chr:GetAttribute("Attacking") == false then
            human.WalkSpeed = 16
            human.JumpPower = 50
        end
    end
end

hello i have a problem with if statement, cuz im making a running and management of walking speed, the function is the where check if a value is on true, and if is pressing the running buttom, the “w”, the “w” have a input event that basicly turns “pressing_runningbutton” on true or false, the problem is that, i have other bool values that you can see, that slow the character, so, specially the “Attacking” attribute, when im running doesnt stop running, but if im not running, its slow down, the “stun” attribute and values that put walkspeed on 0 works even running, so im confused.

and btw im firing a remote event to check and let the server think more better the walkspeed of the player.

Where is pressing_runningbutton changed to true?

here

local maxDelay = 0.25
local t1 = 0

UIS.InputBegan:Connect(function (input, gp)
	if gp == true then 
		return
	end
	if input.KeyCode == Enum.KeyCode.W then
		if no_double_tap == false then
			if tick() - t1 <= maxDelay then
				running:Play()
				pressing_runningbutton = true
				updateSpeed()
			else
				t1 = tick()
			end
		else
			pressing_runningbutton = true
			updateSpeed()
		end
	end
end)

UIS.InputEnded:Connect(function(input, gp)
	if gp == true then 
		return
	end
	if input.KeyCode == Enum.KeyCode.W then
		if pressing_runningbutton == true then
			pressing_runningbutton = false
			updateSpeed()
		end
	end
end)

and this is how i check and updated the function:

chr:WaitForChild("Values").NormalVals.Ragdoll.Changed:Connect(updateSpeed)
chr:GetAttributeChangedSignal("Stun"):Connect(updateSpeed)
chr:GetAttributeChangedSignal("activu"):Connect(updateSpeed)
chr:GetAttributeChangedSignal("Attacking"):Connect(updateSpeed)
chr:GetAttributeChangedSignal("GettingBeatdown"):Connect(updateSpeed)

human.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.PlatformStanding and old == Enum.HumanoidStateType.Running then
		updateSpeed()
	elseif old == Enum.HumanoidStateType.Running and new == Enum.HumanoidStateType.Jumping then
		return
	end
end)

Try adding some print statements:

local pressing_runningbutton = false
local no_double_tap = true
local sprinting = false
local speedremote = replicatedstorage.Basics.WalkSpeedCheck
local running = player.Character.Humanoid:LoadAnimation(script.Running)

local function updateSpeed()
	print("pressing_runningbutton =", pressing_runningbutton)
	local stun = chr:GetAttribute("Stun")
	print("chr:GetAttribute("Stun")", stun)
	if pressing_runningbutton and chr:GetAttribute("Stun") == false then
		human.WalkSpeed = 25
		human.JumpPower = 30
		sprinting = true
		if human.Health > 1 then
			running:Play()
		end
		human.AutoRotate = true
		speedremote:FireServer(pressing_runningbutton)
	else
		running:Stop()
		speedremote:FireServer(pressing_runningbutton)
		sprinting = false
		if chr:GetAttribute("Stun") == true or player.Character:WaitForChild("Values").NormalVals.Ragdoll.Value == true or player.Character:GetAttribute("GettingBeatdown") == true then
			print("Zero")
			player.Character.Humanoid.WalkSpeed = 0
			player.Character.Humanoid.JumpPower = 0
			player.Character.Humanoid.AutoRotate = false
		elseif chr:GetAttribute("Attacking") == true then
			print("Attacking")
			human.WalkSpeed = walk_attack.Value
			human.JumpPower = jump_attack.Value
			human.AutoRotate = true
		elseif chr:GetAttribute("Attacking") == false then
			print("Normal")
			human.WalkSpeed = 16
			human.JumpPower = 50
		end
	end
end

print("chr:GetAttribute("Stun") == false", chr:GetAttribute("Stun") == false)

i dont think is a print thing bro