Blocking Attack Script

  1. Hey guys I am trying to make a block script.

  2. Basically, in my game, there are two kinds of hits, there is the light hit and there is the hard hit. What I am trying to do is that when the player uses the blocking ability on the light attack, he takes 0 damage. When he uses the ability on the hard attack, the blocker still receives 5 damage for example instead of 25.

Please respond fast on this if you know the answer.
Thanks in advance for the help!

When the player’s character is added, add a bool value into their character which should be updated when they start/stop blocking. When another player attacks, check if the blocking value is true and don’t do damage. If they do the strong punch and the value inside the target is true then deal 5 damage instead of 25.

1 Like

Do you have any video or script to explain this?

But I need something that really helps me exactly on this subject, not something that teaches bool values in general.

You’re going to be hard pressed to find any information that helps you with this specifically. You will have to use your coding knowledge to implement this in a way that suits your need. Simplistically, your server structure could look like this:


local blocked = false

local function takeDamage()
	
	if blocked then
		-- Reduce Damage
	elseif not blocked then
		-- Take full damage
	end
end

Of course, there will be multiple players. I suggest storing a table of all players where their specific blocked and attackType variables will be located, of which will be toggled by remote events.

hmm I think I am gonna ask someone in a discord server to help me, because I am not the best to understand all of this

actually no I understand that thing

Well, how are you setting up the game and managing players?

but can you please help me with what you said at the end?:

Of course, there will be multiple players. I suggest storing a table of all players where their specific blocked and attackType variables will be located, of which will be toggled by remote events

It really depends on how you have your game set up. Basically, you want to ensure all damage calculations are handled server side. You will want some way of managing each player’s state. With a simple sword system you could have this situation:

Player X wants to damage Player Z

Since there is no accounting for Player Z’s state (blocked or not blocked) there is no need to store his state. In you scenario, additional checks will need to be done to determine if Player Z is blocking. Take all this with a pinch of salt because I am no expert. However, since each Player’s state will want to be accessed relative to the tool’s script, you’ll need a way to access this. Using remote events to toggle states, you can track these from any script by using the require function to access a module script.

thanks for all that, but I am going to let this post open for more ppl to help since I am not a PRO scripter