I have created a shield model and made the necessary animations and sound effects but how can I make it so that whenever the player equips the shield , any damage done to the player will be reduced to zero. Will really appreciate any help I receive and I have already made an equip function and the code to check whether the tool is equipped or not.
You can create a force field in a server script when player equips shield and remove it when player uneqips it. Note that force field can only protect from,
humanoid:TakeDamage()
If you do,
humanoid.Health = humanoid.Health - 50
Force field will not protect damage in here.
It’s actually pretty simple, in the combat system before applying the damage you only have to check if the enemy receiving the hit has a shield equipped or not if - he has a shield equipped - then just don’t apply the damage.
some pseudocode
if HasShield(Enemy) then
return
else
Enemy:TakeDamage(damage)
end
Sorry for replying late but I want that the player don’t receive any damage from the front but can be damaged from the back. Is there any way to do it?
Well you can just have the shield model be in front of the player
I am sorry but how can I do that ? I didn’t understand your comment completely.
You can add an exception in your weapons before the TakeDamage where it checks if the player has a shield equipped or not.
Yep. Or like @Helyras said, you can give the player a force field when they equip the sheild, then make the Visible property false.
Instead of this I have come up with another idea. I am thinking of making a block breaker attack which will stun the opponent for sometime. Will it be better? For this I will set that as soon as the move is used , shield.equipped will become false. Will this work?
You’ll need dot product to achieve it
You said not damaged from front but damage at back. I think if you were able to get the enemy look vector and a boolean in addition to the great idea about the shield equipped bool.
Basically if they are opposing look vectors then it’s if player’s lookvector is say “Positive” and enemy lookvector is not “positive” then they would be facing each other.
That’s vague but a direction to explore.
Basically it would allow damage I think if the look vector was in similar direction but not if facing. Adjusted numbers by testing.
Easiest way is to say do the shield equipped. I’m not a coding expert but the “shield break” should be a condition too for it.
If enemy shieldBreak == True
Then basically disable forcefield.
Sorry best I got right now.
Or you create shield can collide. But that would not really be best for Roblox I think because it’s not like say a AAA rpg.
Swords are simple.
I would look up lookvector in docs.
Adding the shield disabled means then it would need to end when some time or event happens unless you actually want it to break I guess.
I think it’s simpler to check if the other used the break button before the “then” statement part because it’ll check if the shield is equipped, if the enemy when hit hit the break button, and only if not will create the forcefield.
Thank you very much but I made the attack and it works perfectly fine 