How do I make a blocking animation that does less damage to a player when used

How would I make it so when I click like B for example while holding a sword it plays a blocking animation, and the player takes less damage when he’s using this animation?

I’m assuming you know how to make a B to block animation but not when player takes less damage when he’s using this animation. You can add a less damage variable and a damage variable.

local reduceDamage = 30 -- to what you want
local damage = 45 -- sword damage

Then detect if a player is playing the block animation on a damage script by adding an if statement then damage the player by

player:TakeDamage(damage - reduceDamage)

I don’t know what is your coding in the damage script but I think you will be able to script that.

3 Likes

uis.InputBegan:Connect(function (input, processed)
if processed then return end
if input.KeyCode == Enum.KeyCode.F then
local animation = player.Character.Humanoid:LoadAnimation(block)
animation:Play() wait(1)
animation:Stop()
end
end)
This is my code, how do I make it so a player takes less damage while that animation plays?

You can add a new line of a script after the if statement.

animation:Play() 
player:TakeDamage(damage - reduceDamage)
wait(1)
animation:Stop()

Wait I realized I’m doing this in a local script, you need to fire the event and in the server script, it takes damage. Do you know how to do that?

No, I’m not sure how to fire the event. II think I’ve done something like that before but don’t really remember how to do it.

If you want to fire an event, you have to add a remoteevent, mainly in replicatedstorage, just detect if a player has been damage and if a player is playing the block animation.

Local:

DamageEvent:FireServer(damage, reduceDamage) -- if player blocked
DamageEvent:FireServer(damage) -- if player didn't block

Server:

DamageEvent.OnServerEvent:Connect(function(dmg, redmg) -- Damaged but also blocked
Player:TakeDamage(dmg - reduceDamage)
end)

DamageEvent.OnServerEvent:Connect(function(dmg)  -- Damaged
Player:TakeDamage(dmg)
end)

Do NOT pass damage and the amount of damage to be reduced as a parameter from the client. Any exploiter can fire this remote and change the damage to whatever they please.

The server should be responsible for figuring out how much damage and how much reduced damage a player should take if they’re blocking.