#Not sure why this loop runs one line of code and then end

1 messages · Page 1 of 1 (latest)

grim dome
#
-- 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
#

Referring to line 46 loop.

nocturne vine
#

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 Thumbs http://wiki.roblox.com

Learn with documentation and resources for all creators.

grim dome
nocturne vine
#
while enemyHealth <= 100 do
    task.wait(0.1)
    enemyHealth = enemyHealth - playerDamage```
and
```lua
while enemyHealth <= 0 do
    task.wait(0.5)
    enemyHealth = enemyHealth + 1```
grim dome
nocturne vine
#

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?

grim dome
#

not familiar with the -= operator

nocturne vine
#

change the -damage to +damage and enemyhealth +1 to -1? but i think you meant the first

nocturne vine
#

just shorthand for this common operation

#

exclusive to roblox luau Thumbs

#

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?

grim dome
grim dome