-- HP
local enemyHealth = 100
-- Max Damage
local damageHardCap = 10
-- Minimum Damage
local damageSoftCap = 1
-- Starter Damage
local playerDamage = 5
-- Buff Damage (Added together with playerDamage)
local buffDamage = 7
playerDamage = playerDamage + buffDamage
-- Prevents the player from exceeding the damage hard cap.
while playerDamage >= damageHardCap do
playerDamage = damageHardCap
print("Peak strength: " .. playerDamage)
break
end
playerDamage = playerDamage - buffDamage - buffDamage
-- Prevents the player from going under the damage soft cap.
while playerDamage <= damageSoftCap do
playerDamage = damageSoftCap
print("Weakest strength: " .. playerDamage)
break
end
while enemyHealth <= 100 do
task.wait(0.1)
enemyHealth = enemyHealth - playerDamage
print("Enemy HP: " .. enemyHealth)
if enemyHealth <= 0 then
print("Enemy Dead: " .. enemyHealth)
break
end
end
while enemyHealth <= 0 do
task.wait(0.5)
enemyHealth = enemyHealth + 1
print("Enemy Reviving: " .. enemyHealth)
if enemyHealth >= 100 then
print("Enemy Revived: " .. enemyHealth)
break
end
end
#Not sure why this loop runs one line of code and then end
1 messages · Page 1 of 1 (latest)
it's running once because that's just simply how scripts work. they only run once.
you have no functions, no api events, nothing that would call into your script. you have the function bodies already (the code that actually does the stuff), but no code to put those functions in context. like if you wanted to react to the changes in an enemies health, you might use humanoid:getpropertychangedsignal("health") for example, which you can find in the docs. the docs are your friend
http://wiki.roblox.com
It should be increasing enemyHealth by 1 to 100 and then stop.
oh i think you got your conditions and math backwards there
while enemyHealth <= 100 do
task.wait(0.1)
enemyHealth = enemyHealth - playerDamage```
and
```lua
while enemyHealth <= 0 do
task.wait(0.5)
enemyHealth = enemyHealth + 1```
I'll be sure to look at this, thanks.
you compare <= less than or equal to, and then subtract. that doesn't seem right. did you mean to write while health >=0 do health -= damage end?
or just flip the signs?
not familiar with the -= operator
change the -damage to +damage and enemyhealth +1 to -1? but i think you meant the first
its identical to health = health - damage
just shorthand for this common operation
exclusive to roblox luau 
it doesnt exist in native lua.
and i mean if you really want to go the distance, you should be looking for humanoid:takedamage and humanoid.health, but you do everything with variables, idk did chatgpt write this?
I'm new to learning lua so I'm coding what I know and learn, and putting it into practice. I didn't think about using the humanoid though, I'll be sure to look at it.
Right now I'm figuring out the changes
I'm trying it make it so if enemyHealth is 100 or over that it substracts to 0 and stops.
Also I'm trying to make it so if forever reason that the enemyHealth is below 0 or equal to it, that it adds up to 100 and then stops.