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.
What is the issue?
My elseif returns as a error, not sure why.
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."
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.
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)
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.