You got a ton of stuff wrong here.
First off, the first "if" you have there, doesn't have a then. All if statements must have a "then".
if [condition] then [code] end
again with the if statement. In the condition, you have:
v == player
you are checking if a string is the same as a player.
You need to check if a string is the same as a player name.
if v == player.Name then
in the for statement, you have a then at the end of the first line of it.
for i,v in pairs {Admins} **then**
replace the then with a do
for i,v in pairs {Admins} do
But that's still incorrect.
try calling pairs with parenthesis! ()
for i,v in pairs(Admins) do
there we go!
Also, try and connect the PlayerJoined function with the player.
game.Players.PlayerAdded:connect(PlayerJoined(player))
And we did it!
Technically this is fixed.
But according to us, it's incorrect!
Whenever an admin joins the game, multiple messages overlap each other!
Why? Because it checks for admins every time it runs!
Admins = {'Luistheinge', 'Funkvolume24', 'giganticCRAZYERIC'}
function PlayerJoined(player)
local isAdmin = false
for _,v in pairs(Admins) do
if v:lower() == player.Name:lower() then
isAdmin = true
break
end
end
if (isAdmin == true) then
local m = Instance.new("Message", game.Workspace)
m.Text = "The admin " .. player.Name .. " has joined the server."
wait(5)
m.Parent = nil
end
end
game.Players.PlayerAdded:connect(PlayerJoined(player))
Alright. What did I do?
Well. Look at the for loop. I put an underscore there because we don't need the "i" variable. It is completely optional to remove the "i" variable but it makes the script cleaner.
I also did v:lower() and player.Name:lower(). lower() is a function to find the lowercase version of a string.
Example:
Example = "UPPERCASE"
print(Example:lower())
Output: "uppercase"
I also used, 'break'.
Break breaks any loop.
Example:
while true do
print("HI")
break
end
output: HI
Do you know what local variables are?
Local variables are local. (duh) Meaning they are only accessible by the function, loop, if, etc it is in.
Example:
if true then
local x = 1
print(x)
end
print(x)
output: 1, nil
I hoped this helped.
If you're new to lua, I recommend you read programming in lua.
Here is a free version online:
Programming in lua
And also, if you feel stupid reading my answer. Don't feel that way. Programming isn't something you learn instantly. It takes time to figure it out. I remember when I didn't know how to connect a function to an event. Lol.
2 comments
When connecting events, you don't call the function and supply arguments, you just give the function name, such as: script.Parent.Touched:connect(onTouched)
wiki.roblox.com/index.php?title=RBXScriptSignal#Usage