#Game keeps trying to subtract 0

1 messages · Page 1 of 1 (latest)

opal jetty
#

I'm working on a tycoon game and have the basic buying coded how ever I want to have the first button set to be free so i set the price as 0 problem is the equation I have to subtract from players cash it out puts an error about how it can't subtract from 0. So I go to fix the problem but whenever I attempted an If else statement the script freaks out and Multiple errors pop up that don't actually when I investigate them.

old dove
#

make an if statment

opal jetty
#

the most stable solution I've found but I'm not sure how to resolve when the Price equal to or less than 0

old dove
#

bro

leaden niche
old dove
#

just say if price >= 0 then give the tycoon item

#

No need to subtract 0

opal jetty
#

if i remove the else it breaks something in a completely different place

old dove
#

You dont need it

leaden niche
leaden niche
opal jetty
#

07:35:24.561 ServerScriptService.TycoonHandler:52: attempt to perform arithmetic (sub) on number and nil

#

that

#

it only happens if the price is set to 0

leaden niche
lethal veldt
#

no, that means you're doing number - nil

#

which is in fact performing an arithmetic sub on number and nil

opal jetty
#

it's trying to subtract 0 from the leaderboard, lua can't subtract by 0

lethal veldt
#

no, read the error

#

there is something in your code that is making that you're subtracting nil to a number

opal jetty
#

The error does not occur if price value I have set for the button is not zero, if only occurs if the price I have set on the button is zero.

dreamy gobletBOT
#

studio** You are now Level 1! **studio

lethal veldt
#

that is not what I'm talking about, the error is what it is, and it is saying you're subtracting nil to a number

#

check that out

opal jetty
#

Nil is 0

fleet oar
lethal veldt
#

no

leaden niche
sharp meteor
#

Just give the full code

opal jetty
#

there

clear parcel
#

Have it print(Price) before subtracting it. If that prints Nil, then just add a if not Price then Price = 0 end

dreamy gobletBOT
#

studio** You are now Level 3! **studio

opal jetty
#

print(Price) if Price ~= nil then Price = 0 would this work to convert nil to zero

leaden niche
# opal jetty

The price subtraction is outside of the check to see if Price (which is an attribute) is even there

That could be why it's subtracting nil

leaden niche
opal jetty
leaden niche
opal jetty
leaden niche
opal jetty
#

the one and only button's price is 0 it has been set to this whole time, it for no explainable reason is reading that 0 as nil

leaden niche
opal jetty
#

ugh I think I found figured it out, lua is case sensitive the number on the button is under price with an uppercase P and it want's price withe a lower case p... im going to do somthing

leaden niche
opal jetty
#

hold on let me test it now that ive fixed that

dreamy gobletBOT
#

studio** You are now Level 2! **studio

opal jetty
clear parcel
opal jetty
#

nope

#

it just prints 0

clear parcel
#

There aren’t any prints in that code, are you sure you’re looking in the right place?

leaden niche
# opal jetty

You don't need to check if Price is nil anymore, so you can get rid of the if Price then statement

opal jetty
#

i look in the output when i test and it just says 0 x amount of times

leaden niche
opal jetty
#

thats not what that was for

clear parcel
#

The print will probably show what line it’s from, go look there

opal jetty
#

i somehow fixed it the problem on my own

#

i undid something and now no errors, no clue what

#

I hate lua

leaden niche
# opal jetty I hate lua

I mean this is just programming in general lol, you're going to create bugs and fix bugs then make more bugs

opal jetty
#

im.. im going to bed

fervent bronze
#

instead of buying the free upgrade. why not remove the entire buying idea and just trigger the upgrade right as its touched??