Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't these short lines of code work?

this script will keep printing ("health") even when the health of blueRed or blueYellow is 0? why

local space = game.Workspace
local center = space.center.Humanoid
local blueRed = space.blueRed.Humanoid
local blueYellow = space.blueYellow.Humanoid



while true do
	wait()
if blueRed.Health or blueYellow.Health  > 0 
then
	
	center.MaxHealth = math.huge
	print ("health")
		center.Health = math.huge
	else
			print ("dead")
center.MaxHealth = 1000
center.Health = 1000
			
	end
end



2 comments

0

More explain on what your doing?

0

im tryna make the center have unlimited hp while "blueRed" and "blueYellow" are more than 0 hp (not dead). so once either blueRed or blueYellow reaches 0 hp the system should print "dead" but it's not

1 answer

It is caused by this

if blueRed.Health

This is because you did not compare blueRed.Health to anything meaning that as long as it is not nil it will pass. To fix this, simply check if blueRed.Health is more than 0 and it should work.

local space = game.Workspace
local center = space.center.Humanoid
local blueRed = space.blueRed.Humanoid
local blueYellow = space.blueYellow.Humanoid

while true do
    wait()
    if blueRed.Health > 0 or blueYellow.Health > 0 then
        center.MaxHealth = math.huge
        print("health")
        center.Health = math.huge
    else
        print("dead")
        center.MaxHealth = 1000
        center.Health = 1000
    end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.