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)