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

How do I compare two GUI's text?

Asked by 2 years ago

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?

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. PaleNoobs 37 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago

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.

Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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
0
I meant comparing as in greater (>) or less than (<) jaddub2008 22 — 2y
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(). LordKrox 39 — 2y

Answer this question