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

How do I compare two GUI's text?

I am just messing around with random numbers and was trying to make a system that would update every time a higher number is generated.

local rtext = script.Parent.Parent.Random
local htext = script.Parent

htext.Text = 0

while true do
	wait(.01)
	if rtext.Text > htext.Text then
		htext = rtext
	end
end

When I run this the console says I am trying to compare nil values, is there an easy way to make the text from a GUI into an integer value?

1 comment

0

on line 8, you may want to change them to “if tonumber(rtext.Name) > tonumber(htext.Name) then”. tonumber() can change any string variable or instance into a readable format for the computer, so it’s best to use this function when reading numbers off of a string.

2 answers

✓ Accepted answer

Tonumber() can solve your issue

local rtext = script.Parent.Parent.Random
local htext = script.Parent

htext.Text = tostring(0)

while true do
    wait(.01)
    if tonumber(rtext.Text) > tonumber(htext.Text) then
        htext = rtext
    end
end

It converts any given value to a number if possible.

Its because rtext doesnt have text, also because you used =, instead of == to compare values. Here is the script btw: I also used A and B instead of rtext and htext, so change it however you'd like.

local A = script.Parent.A
local B = script.Parent.B

B.Text = 0
A.Text = 0
while true do
	wait(.01)
	if A.Text == B.Text then
		B = A
	end
end

2 comments

0

I meant comparing as in greater (>) or less than (<)

0

Just Replace (==) with (>) or (<), you just need to make scripts in the TextBoxes to update using basic variables, or do what the other guy said and use Tonumber().

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