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

Help on a script, please.?

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?

1 comment

0

Added a code block, apologies.

1 answer

✓ Accepted answer

#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)

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