01 | local b = script.Parent |
02 | local guess = b.Parent.Guess |
03 | local nums = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } |
04 | local num = nums [ math.random( 1 , #nums) ] |
05 |
06 | b.MouseButton 1 Click:connect( function () |
07 | if guess.Text = = num then |
08 | print ( "yay" ) |
09 | end |
10 | end ) |
11 |
12 | print (num) |
The problem is, this doesn't print "yay" when i enter the correct bumber, why is this?
The problem lies in line 7. I'm going to assume that b
is a TextButton object. Look for "Text", the third entry down in "Properties." Next to it says "string." That means this property accepts strings. So you can do either the following: convert guest.Text
into a number, or convert num
into a string.
1 | if tonumber (guess.Text) and tonumber (guess.Text) = = num then |
Or
1 | if guess.Text = = tostring (num) then |