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

why wont label text change to typed value?

Asked by 8 years ago

the label text on surface gui wont change to the number typed into the textbox, which has to be one of the numbers in the table, please help.

local tbl = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99}
plr = script.Parent.Parent.Parent.Parent.Parent
char = plr.Character
 vl = Instance.new("SurfaceGui", char.Torso)
vll = Instance.new("Frame", vl)
vlll = Instance.new("TextLabel", vll)
vll.Size = UDim2.new(0,800,0,600)
vll.Transparency = 1
vlll.FontSize = "Size96"
script.Parent.MouseButton1Down:connect(function()
    for i,v in pairs(tbl) do
        if script.Parent.Parent.NumberHere.Text == v then
        vlll.Text = v
    end
    end
end)

?

1 answer

Log in to vote
3
Answered by
theCJarmy7 1293 Moderation Voter
8 years ago

Ok, there are a few flaws in this. Firstly, your table gets cut off, secondly, there is this magic function called tonumber.

local max = 20 --change this to the biggest number in the table

script.Parent.MouseButton1Click:connect(function()
    local num = script.Parent.Parent.NumberHere.Text
    if tonumber(num) then --check if it's a num
        if tonumber(num)<=max then --check if it's under the max
            vlll.Text = num
        end
    end
end)
Ad

Answer this question