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

Help on a script, please.?

Asked by
raid6n 2196 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

I am working on a script when you type in a number 1-18 in a button and you click a submit button, a gui will change color.

I typed in the script

script.Parent.MouseButton1Click:connect( function()
     for i = 1,18,1 do wait()
         if script.Parent.Parent.TableHandler.Text == i then
             game.Players.LocalPlayer.PlayerGui.TableFinder.TableLots["Table"..i].BackgroundColor3 = Color3.fromRGB(255,0,0)
         end 
    end 
end)

and it ended up not working.

Could someone send me a script that would make this work?

0
Added a code block, apologies. raid6n 2196 — 5y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Edit to anyone viewing this:

OP first had to convert his text to a number so we're using tonumber() to convert that. We also changed the comparison to an if statement so we're only making one comparison compared to 18. After we ran this script, we got some errors so we looked in studio to see why it wasn't working and it turns out that the script was a regular script instead of a localscript so we couldn't access the local player. When we changed it to a local script it worked fine.

LocalPlayer = game.Players.LocalPlayer
tableLots = script.Parent.Parent.Parent.TableLots

script.Parent.MouseButton1Click:connect(function()
    local text = script.Parent.Parent.TableHandler.Text
    local number = tonumber(text)
    print("Number ", number)

    if number >= 1 and number <= 18 then
        local chosenTable = tableLots["Table"..tostring(number)]
        print("Table ", chosenTable)
        chosenTable.BackgroundColor3 = Color3.fromRGB(255,0,0)
    end
end)
Ad

Answer this question