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

This doesn't print "yay" when correct?

Asked by
wackem 50
9 years ago
local b = script.Parent
local guess = b.Parent.Guess
local nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
local num = nums[math.random(1, #nums)]

b.MouseButton1Click:connect(function()
    if guess.Text == num then
        print("yay")
    end
end)

print(num)

The problem is, this doesn't print "yay" when i enter the correct bumber, why is this?

0
please put your code in a code block YellowoTide 1992 — 9y
0
done wackem 50 — 9y

1 answer

Log in to vote
2
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

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.

if tonumber(guess.Text) and tonumber(guess.Text) == num then

Or

if guess.Text == tostring(num) then
Ad

Answer this question