Why do my elseif is invalid

  1. What do you want to achieve?
    I try to makes a scripted text so if they are in a certain table they get a banned text.

  2. What is the issue?
    My elseif returns as a error, not sure why.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried using else but still returning as error.

local TL = script.Parent
local Banned = {"achdef"}

game.Players.PlayerAdded:Connect(function(plr)
TL.Text = "Welcome to LUA LEARNING, " ..plr.Name
elseif table.find(Banned, plr.name) then -- Error line is here.
TL.Text = "You are not supposed to be in-game."
1 Like

you should use a for i, v loop to get all of the strings inside the table. And then after that compare the player’s name with the strings inside the table.

The ‘elseif’ is not enclosed in an ‘if’ statement, so it’s being flagged.

1 Like

Now its my end returning as a error.

try this

local TL = script.Parent
local Banned = {"achdef"}

game.Players.PlayerAdded:Connect(function(plr)
    TL.Text = "Welcome to LUA LEARNING, " ..plr.Name
    if table.find(Banned, plr.name) then -- Error line is here.
        TL.Text = "You are not supposed to be in-game."
    end
end)
1 Like

Working, thanks you so much for the help!

1 Like

As @Self_Reflexive stated, the problem is because you use elseif as a another condition to check after an if. Try this instead

local TL = script.Parent
local Banned = {"achdef"}

game.Players.PlayerAdded:Connect(function(plr)
   if table.find(Banned, plr.Name) then 
      TL.Text = "You are not supposed to be in-game."
   else
      TL.Text = "Welcome to LUA LEARNING, " ..plr.Name
   end
end)

This way it also changes the text if you aren’t banned instead of changing the text and then checking if you’re banned

if statement hasn’t been declared, that’s why else or elseif will be invalid as they can only be used with the if statement.
Fixed script:

local TL = script.Parent
local Banned = {"achdef"}

game.Players.PlayerAdded:Connect(function(plr)
    TL.Text = "Welcome to LUA LEARNING, " ..plr.Name

    if table.find(Banned, plr.name) then -- Changed elseif to if
        TL.Text = "You are not supposed to be in-game."
    end -- You also forgot "end" :)
end) -- And the end of connection as well :)

@james_mc98, you don’t necessarily have to do that, table.find() works perfectly fine in this scenario.

Ah, got it but someone said it first.

Alright, glad you eventually got your answer though! If you ahev anymore issues don’t be afraid to make another post!

table.find do that but in another type.