Hello! I am making a combat system for my game. I wanted to know how to add a hitstun to my combat. By hitstun i mean setting ‘hits’ (humanoid that was hit) walkspeed to 0 and then when my combo ends or when i stop attacking it goes back to their previous walkspeed. I have already tried this but i had a problem, it will work the first time if i punch them once every second they will get stunned for the time specified and go back to normal but, if i hit that humanoid twice in under a second, their walkspeed overides because everytime they get hit im setting their currently walkspeed to a variable. So if their stunned while i hit them then that walkspeed is now the stuns walkspeed since its setting to their current walkspeed everytime it hits. Is their a way to get around this and like store the walkspeed once when i punch them? but able to keep stunning them if i keep punching more than once in a quick succession (sorry for the paragraph)
TLDR: How To Stun A Humanoid With Combos
Hit Script
fist.Parent = workspace
touchConn = fist.Touched:Connect(function(hit)
if hit:isA(“BasePart”) then
if hit.Parent:FindFirstChild(“Humanoid”) then
if hit.Parent.Name ~= player.Name then
if hit.Parent.Humanoid.Health > 0 then
if not beenhit[hit.Parent] then
if count < 5 then
damageFunctions.doDamage(hit.Parent.Humanoid,damage,player)
else
damageFunctions.doDamage(hit.Parent.Humanoid,damage*1.5,player)
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = (character.HumanoidRootPart.CFrame.LookVector * 70 + Vector3.new(0,20,0))
bv.Parent = hit
spawn(function()
wait(.3)
bv:Destroy()
end)
end
hitting = hitting + 1
local play = hit.Parent.Humanoid:LoadAnimation(anims[count])
play:Play()
spawn(function()
while hitting > 0 do
hitting = hitting - 0.1
if hitting > 0 then
if hit.Parent then
hit.Parent.MoveCoolDown.Value = true
end
else
hit.Parent.MoveCoolDown.Value = false
end
wait(0.1)
end
end)
beenhit[hit.Parent] = true
if count < 5 then
sound.Parent = hit
sound:Play()
else
local Heavy = sound.Heavy:Clone()
Heavy.Parent = hit
Heavy:Play()
spawn(function()
wait(1)
Heavy:Destroy()
end)
end
wait(0.2)
beenhit[hit.Parent] = false
fist:Destroy()
if touchConn ~= nil then touchConn:Disconnect() end
fist:Destroy()
end
end
end
end
end
end)