Why Stunned Value will never become false?

So i’ve been trying to make a combat system but i’ve ran into the issue where StunTime will never become 0 but how do i fix that?

--//Services
local Run_Service = game:GetService("RunService")
local Replicated_Storage = game:GetService("ReplicatedStorage")

--//Tool
local Tool = script.Parent.Parent

--//Events
local Events_Folder = Tool.Events

local Damage_Remote = Events_Folder.DamageRemote

--//Values
local Stun_Time = 0

--//Particles
local Combat = Replicated_Storage.Combat
local Gore = Combat.Gore

--| Main Script |--
function Damage_Target(Player, Target, Damage, Body_Part)
	local Target_Humanoid = Target.Humanoid
	local Stunned = Target:WaitForChild("Stun")
	
	Target_Humanoid.Health -= Damage
	Stun_Time = 1
	local Blood_Clone = Gore.Blood:Clone()
	Blood_Clone.Parent = Body_Part
	Blood_Clone:Emit(50)
	
	Stunned.Value = true
	print(Stunned.Value)
	
	task.wait(Stun_Time)
	Blood_Clone:Destroy()
	
	if Stun_Time <= 0 then
	Stunned.Value = false
	print(Stunned.Value)
	end
end

function Update_Stun_Time()
	if Stun_Time >= 0 then
		Stun_Time -= Run_Service.Heartbeat:Wait()
	end
end


Run_Service.Heartbeat:Connect(Update_Stun_Time)

Damage_Remote.OnServerEvent:Connect(Damage_Target)
1 Like

You should change it to this, if stuntime is still bigger than 0 then it will stop completely

repeat wait() until Stun_Time <= 0 -- waits until stun time is 0
Stunned.Value = false
	print(Stunned.Value)
1 Like

after i did it it started changing value to false even after i hit a humanoid

https://streamable.com/g756st

1 Like

You made me extremely confused. In the video the script sets the stun value to false 1 second after the last time you hit the humanoid. What do you want to do again?

1 Like

i am making a stun system, every time you hit a humanoid stun time Resets but for some reason stun time doesn’t reset

1 Like

Try printing the stun time in Update_Stun_Time to find if it is reset to 1 every time the humanoid got hit

i did, stun time doesn’t want to reset
https://streamable.com/osmcf4

umm sorry to interrupt but the video broke I can’t access it, send it again

https://streamable.com/xi9dud
here