Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to fix the attempt to compare boolean with number error roblox?

Asked by 8 years ago
Edited by BlueTaslem 8 years ago

The error is Players.Player1.PlayerGui.EggSellGui.MainFrame.ShopFrame.BuggyEgg.LocalScript:29: attempt to compare boolean with number

the error is: if player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value == player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value <= 30 then

My script is:

01local button = script.Parent
02local cost = 30
03local egg = script.Parent.Parent.Parent:WaitForChild("EggImage")
04local choice1 = script.Parent.Parent.Parent:WaitForChild("Choice1")
05local choice2 = script.Parent.Parent.Parent:WaitForChild("Choice2")
06local choice3 = script.Parent.Parent.Parent:WaitForChild("Choice3")
07local costlabel = script.Parent.Parent.Parent:WaitForChild("Cost")
08local player = game.Players.LocalPlayer
09local hatchingmoment = script.Parent.Parent.Parent.Parent:WaitForChild("HatchingMoment")
10local hatchedimage = script.Parent.Parent.Parent.Parent.HatchingMoment:WaitForChild("HatchedImage")
11 
12button.MouseEnter:connect(function()
14    choice1.Image = "http://www.roblox.com/asset/?id=711466052"
15    choice2.Image = "http://www.roblox.com/asset/?id=711466415"
View all 43 lines...

error is on if player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value == player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value <= 30 then

Please help fix

0
Edited to fix code formatting BlueTaslem 18071 — 8y
0
The error is self-explanatory you are using <= with a boolean value ie true <= which is not valid. User#5423 17 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

Well you are comparing a boolean with a number. num == num returns a boolean as well as num <= num. and you have it as num == num -> False <= num (which throws the error when comparing the boolean with a number).

A simple fix is to add and in the if statement, so it should be like this:

1if player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value == player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value and player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value <= 30 then

Also, comparing a value with itself will always return true and a little suggestion, make player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value a local variable since you use it several times.

Ad

Answer this question