so basically i want to make a move in my fighting game that allows the player to gain stacks of protection that can be consumed to stop the player from taking damage.
idk how to do this though
so basically i want to make a move in my fighting game that allows the player to gain stacks of protection that can be consumed to stop the player from taking damage.
idk how to do this though
I would highly reccomend using a modulescript to manage health and other attributes. Here’s an example of one.
local HealthModule = {}
HealthModule.Health = 100
HealthModule.MaxHealth = 100
HealthModule.Shields = 4
function HealthModule.TakeDamage(Damage) --//If more parameters are needed, consider using a dictionary.
--//If there's a shield, remove 1 and end the function
if HealthModule.Shields > 0 then HealthModule.Shields -= 1 return end
HealthModule.Health -= Damage
if HealthModule.Health <= 0 then
--//Kill character.
end
end
return HealthModule
And here’s how to use a module script.
local EnemyModule = require(Enemy.HealthModule) --//Path to enemy's HealthModule
EnemyModule.Shields = 0
EnemyModule.TakeDamage(25)
print(EnemyModule.Health) --75
EnemyModule.Shields = 1
EnemyModule.TakeDamage(25)
print(EnemyModule.Health) --75, broke shield
EnemyModule.TakeDamage(25)
print(EnemyModule.Health) --50
thank you, you responded so fast! this looks like it works so ill try it tommorow morning and let you know the results
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.