Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This doesn't print "yay" when correct?

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?

2 comments

0

please put your code in a code block

0

done

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.