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

attempt to compare boolean and number error?

For my game i need an animation to play, and when the health changes it checks to see if it needs to change animation, but using this code it always gets this error

10:47:24.822 - Workspace.Tower.Dummy.Script:13: attempt to compare boolean and number

Here's the troublesome code: (if anyone can help me make a better less messy version of this code, it would be greatly appreciated)

local function CheckHealth()
	if game.Workspace.Tower.Configuration.Health.Value > 75 then
	local anim1	= script.Parent.Humanoid:LoadAnimation(script.FullAnim)
		anim1.Looped = false
		game.Workspace.Tower.sword1.Transparency = 0
		anim1:Play()
	elseif game.Workspace.Tower.Configuration.Health.Value < 50 then
		if not game.Workspace.Tower.Configuration.Health.Value < 25 then
			local anim2	= script.Parent.Humanoid:LoadAnimation(script.FiftyAnim)
		anim2.Looped = false
		game.Workspace.Tower.sword1.Transparency = 1
		anim2:Play()
		end
		
	elseif 	game.Workspace.Tower.Configuration.Health.Value < 25 then
			local anim3	= script.Parent.Humanoid:LoadAnimation(script.TwentyFiveAnim)
		anim3.Looped = false
		game.Workspace.Tower.sword1.Transparency = 1
		anim3:Play()
	elseif game.Workspace.Tower.Configuration.Health.Value == 0 then
		game.Workspace.Fail:Play()
		local anim4	= script.Parent.Humanoid:LoadAnimation(script.ZeroAnim)
		anim4.Looped = false
		game.Workspace.Tower.sword1.Transparency = 1
		anim4:Play()
		
		
	end
end

2 comments

0

My Eyes are bleeding Right now from looking at this code ! Please Indent more ! And Where is the line of error?

0

sorry about the messy code lol, i made it at 2am the error is on line 8

1 answer

✓ Accepted answer

change line 8 into

if not (game.Workspace.Tower.Configuration.Health.Value < 25) then

atm its doing this

if (not game.Workspace.Tower.Configuration.Health.Value) < 25 then

which turns it into a boolean and thus your are comparing a boolean and a number

also this is how you correctly indent your code

local function CheckHealth()
	if game.Workspace.Tower.Configuration.Health.Value > 75 then
		local anim1 = script.Parent.Humanoid:LoadAnimation(script.FullAnim)
		anim1.Looped = false
		game.Workspace.Tower.sword1.Transparency = 0
		anim1:Play()
	elseif game.Workspace.Tower.Configuration.Health.Value < 50 then
		if not game.Workspace.Tower.Configuration.Health.Value < 25 then
			local anim2 = script.Parent.Humanoid:LoadAnimation(script.FiftyAnim)
			anim2.Looped = false
			game.Workspace.Tower.sword1.Transparency = 1
			anim2:Play()
		end
	elseif  game.Workspace.Tower.Configuration.Health.Value < 25 then
		local anim3 = script.Parent.Humanoid:LoadAnimation(script.TwentyFiveAnim)
		anim3.Looped = false
		game.Workspace.Tower.sword1.Transparency = 1
		anim3:Play()
	elseif game.Workspace.Tower.Configuration.Health.Value == 0 then
		game.Workspace.Fail:Play()
		local anim4 = script.Parent.Humanoid:LoadAnimation(script.ZeroAnim)
		anim4.Looped = false
		game.Workspace.Tower.sword1.Transparency = 1
		anim4:Play()
	end
end

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