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:
01 | local button = script.Parent |
02 | local cost = 30 |
03 | local egg = script.Parent.Parent.Parent:WaitForChild( "EggImage" ) |
04 | local choice 1 = script.Parent.Parent.Parent:WaitForChild( "Choice1" ) |
05 | local choice 2 = script.Parent.Parent.Parent:WaitForChild( "Choice2" ) |
06 | local choice 3 = script.Parent.Parent.Parent:WaitForChild( "Choice3" ) |
07 | local costlabel = script.Parent.Parent.Parent:WaitForChild( "Cost" ) |
08 | local player = game.Players.LocalPlayer |
09 | local hatchingmoment = script.Parent.Parent.Parent.Parent:WaitForChild( "HatchingMoment" ) |
10 | local hatchedimage = script.Parent.Parent.Parent.Parent.HatchingMoment:WaitForChild( "HatchedImage" ) |
11 |
12 | button.MouseEnter:connect( function () |
13 | egg.Image = "http://www.roblox.com/asset/?id=6811340" |
14 | choice 1. Image = "http://www.roblox.com/asset/?id=711466052" |
15 | choice 2. Image = "http://www.roblox.com/asset/?id=711466415" |
error is on if player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value == player:WaitForChild("leaderstats"):WaitForChild("GrassTokens").Value <= 30 then
Please help fix
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:
1 | if 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.