How do I make it so the stun boolen only adds to the enemy character when the player is actually hit and not blocking. I tried different ways to do this but it didn’t work so I’m hoping someone knows the answer.
Video Example:
CombatRemote.OnServerEvent:Connect(function(plyer, data,char) --Accessing all of our data through the variable we put into the "Data" table in the local script.
plyer.Character.HumanoidRootPart.Anchored = false
if data.action == "slash" then
for i, player in pairs(game.Players:GetChildren()) do
if player ~= plyer then
CombatRemote:FireClient(player, data)
end
end
elseif data.action == "hit"and data.MyCharacter:FindFirstChild("Stun") == nil then
SwordSlash:Play()
CombatRemote:FireAllClients(data)
for i, v in pairs(data.hitbox) do
if v:FindFirstChild("Block") then
if v.Block.Value == true then
SwordClashSound:Play()
local NewAnimation = Instance.new("Animation")
NewAnimation.AnimationId = data.deflects[data.combo]
print(data.combo)
local LoadBlockingAnims = v.Humanoid:LoadAnimation(NewAnimation):Play()
NewAnimation:Destroy()
else
-- if they stop blocking they will take damage
local EnemyHumanoid = v.Humanoid
SwordSlashPlayer:Play()
local HitAnimation = Instance.new("Animation")
HitAnimation.AnimationId = data.PlayerHit[data.combo]
local LoadHits = v.Humanoid:LoadAnimation(HitAnimation):Play()
v.Humanoid:TakeDamage(10)
print(EnemyHumanoid.Health)
end
else
-- if they don't have the blocking variable in the first place they will take damage
v.Humanoid:TakeDamage(10)
end
local EnemyHumanoidRoot = v.HumanoidRootPart
local EnemyHumanoidVelocityForce = data.MyCharacter.HumanoidRootPart.CFrame.LookVector
if data.combo == 5 then
EnemyHumanoidRoot.Velocity = EnemyHumanoidVelocityForce * 100
print("ULTIMATE VELOCITY!")
else
EnemyHumanoidRoot.Velocity = EnemyHumanoidVelocityForce * 45
end
local MyHumanoidRoot = data.MyCharacter.HumanoidRootPart
local MyHumanoidVelocityForce = MyHumanoidRoot.CFrame.LookVector
if data.combo == 5 then
MyHumanoidRoot.Velocity = MyHumanoidVelocityForce * 100
print("Hello Server!")
elseif v:FindFirstChild("Stun") then v:FindFirstChild("Stun"):Destroy()
MyHumanoidRoot.Velocity = MyHumanoidVelocityForce * 45
print("Hi Server")
end
local stun = Instance.new("BoolValue", v)
stun.Name = "Stun"
stun.Value = false
game.Debris:AddItem(stun, 1)
end
elseif data.action == "block" then
if data.Character:FindFirstChild("Block") then
data.Character.Block.Value = true
else
-- if didn't have boolen value of block then give
local Block = Instance.new("BoolValue", data.Character)
Block.Value = true
Block.Name = "Block"
end
elseif data.action == "unblock" then
if data.Character:FindFirstChild("Block") then
data.Character.Block.Value = false
end
end
end)