First, I typed in a local script into a text button.
Here's the script:
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) elseif chosenTable.BackgroundColor3 == Color3.fromRGB(255,0,0) then script.Parent.Text = "Table already taken." wait(5) script.Parent.Text = "Please try again." wait(5) script.Parent.Text = "Submit" end end
As I type in elseif and the continued script, nothing works.
It would be wonderful if someone explained the elseif part.
chosenTable was out of scope (meaning the variable doesn't exist in the current context.)
Looking at the rest of your code, it seems like you're trying to alert the player that a table is taken.
If you were to put the code in an elseif, it would only run the code when the table number is either less than 1 or greater than 18, which isn't what we want to do.
We instead need to put the check to see if the table is empty inside the first if statement.
player inputs a number
if the number is between 1-18, the table number is valid then check if the valid table is taken, alert the player that it's taken and let them try again.
if the table is not not taken, give that player that table
if the number is greater than 18 or less than one, the player typed in an invalid table. we tell them that it is invalid and let them try again.
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)] if(chosenTable.BackgroundColor3 == Color3.fromRGB(255,0,0))then script.Parent.Text = "Table already taken." wait(3) script.Parent.Text = "Please try again." wait(3) script.Parent.Text = "Submit" else chosenTable.BackgroundColor3 = Color3.fromRGB(255,0,0) end else script.Parent.Text = "There are only 18 tables.\n Please enter another table number." end end)
There are a few things wrong.
-- these variables should be local because i'm assuming this isn't inside a function local LocalPlayer = game.Players.LocalPlayer local tableLots = script.Parent.Parent.Parent.TableLots -- changed "connect" to "Connect", since "connect" is deprecated. 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) -- elseif should be put together. elseif chosenTable.BackgroundColor3 == Color3.fromRGB(255,0,0) then script.Parent.Text = "Table already taken." wait(5) script.Parent.Text = "Please try again." wait(5) script.Parent.Text = "Submit" end end) -- You forgot the closed parenthesis
Haven't tested it, but fixed a lot of the formatting of this script.
I'm assuming it's very old code. I also recommend using
Activated
instead of MouseButton1Click
and Activated makes it compatible across all devices.
Accept this answer if it helped.