Help with stun when hit

Ok so I have this script with combo parts combo 1 - 5 I would like to know if there is a way I can make where when you get hit you play an animation and

The script has 1 main and 3 sub also one is local

This is the main
script https://www.youtube.com/watch?v=MPHMDBa1EwE

local Cooldown = false

local CanDamage = false

local Combo = 1

local Delay = .65

game.ReplicatedStorage.PunchEvent.OnServerEvent:Connect(function(Player)

if Cooldown then return end

for _, v in pairs(Player.Character:GetChildren()) do

if v:IsA(“Tool”) then return end

end

spawn(function()

Cooldown = true

wait(Delay)

Cooldown = false

end)

local Swoosh = Instance.new(‘Sound’,Player.Character.HumanoidRootPart)

Swoosh.SoundId = ‘rbxassetid://231731980’

Swoosh.Volume = .2

Swoosh.EmitterSize = 100

local rightPunch = Instance.new(“Animation”)

rightPunch.AnimationId = “rbxassetid://5346044818”

local rightTrack = Player.Character.Humanoid:LoadAnimation(rightPunch)

local leftPunch = Instance.new(“Animation”)

leftPunch.AnimationId = “rbxassetid://5345920226”

local leftTrack = Player.Character.Humanoid:LoadAnimation(leftPunch)

local Finisher = Instance.new(“Animation”)

Finisher.AnimationId = “rbxassetid://5350338921”

local finalKick = Player.Character.Humanoid:LoadAnimation(Finisher)

if Combo == 1 then

rightTrack:Play()

Swoosh:Play()

local Dmg = script.RightArm:Clone()

Dmg.Parent = Player.Character[“Right Arm”]

Dmg.Disabled = false

wait(Delay)

Dmg.Disabled = true

Dmg:Destroy()

Combo = 2

else if Combo == 2 then

leftTrack:Play()

Swoosh:Play()

local Dmg = script.LeftArm:Clone()

Dmg.Parent = Player.Character[“Left Arm”]

Dmg.Disabled = false

wait(Delay)

Dmg.Disabled = true

Dmg:Destroy()

Combo = 3

else if Combo == 3 then

rightTrack:Play()

Swoosh:Play()

local Dmg = script.RightArm:Clone()

Dmg.Parent = Player.Character[“Right Arm”]

Dmg.Disabled = false

wait(Delay)

Dmg.Disabled = true

Dmg:Destroy()

Combo = 4

else if Combo == 4 then

leftTrack:Play()

Swoosh:Play()

local Dmg = script.LeftArm:Clone()

Dmg.Parent = Player.Character[“Left Arm”]

Dmg.Disabled = false

wait(Delay)

Dmg.Disabled = true

Dmg:Destroy()

Combo = 5

else if Combo == 5 then

finalKick:Play()

Swoosh:Play()

local Dmg = script.Finisher:Clone()

Dmg.Parent = Player.Character[“Right Leg”]

Dmg.Disabled = false

wait(Delay)

Dmg.Disabled = true

Dmg:Destroy()

Combo = 1

end

end

end

end

end

end)

image|267x362

1 Like

Just a thing but use the code block image And then put the code inside.

Your code is virtually unreadable due to the lack of a codeblock. For future reference, code blocks are made with: ```

To simulate a stun, you can use a property of Humanoid called PlatformStand, setting it to true to stun the player and setting it to false to unstun them.

Example Code:

script.Parent.Touched:Connect(function(hit)
    if hit and hit.Parent:FindFirstChild("Humanoid") then then
        humanoid = hit.Parent.Humanoid
        humanoid.PlatformStand = true -- Stun
        wait(5)
        humanoid.PlatformStand = false -- Unstun
    end
end)

S_maritan, your code includes the “then then” after line 2. So it’s best if you edit it to

    if hit and hit.Parent:FindFirstChild("Humanoid") then 
        humanoid = hit.Parent.Humanoid
        humanoid.PlatformStand = true -- Stun
        wait(5)
        humanoid.PlatformStand = false -- Unstun
    end
end)

I just wanna say something about what S_maritan said, this will cause overlapping issues, for loose hits it’ll work i guess, but when taking combos into account this method will definitly ruin it

using platformstand itself is fine, just the way unstunning is handled causes this issue

So what would be the best way to handle this without overlapping issues?

1 Like