Admins = {} -- Up to 3 Admins Children = {} -- Do not touch function Children(player) -- This will turn everyone who isn't part of the list into children local Player = player:GetFullName() print(player) if Player.UserID == Admins[1] or Player.UserID == Admins[2] or Player.UserID == Admins[3] then print("DayCareWorker") end if Player.UserID ~= Admins[1] or Player.UserID ~= Admins[2] or Player.UserID ~= Admins[3] then print("Child") end end game.Players.PlayerAdded:connect(Children)
This is my FIRST time trying to work with a table, and I'm clearly not understanding it enough.
I haven't gotten to the big stuff, but the first IF statement is suppose to send the message Daycareworker in the output, but if that isn't true then it'll skip over that and then head to the second one in this function and print Child.
I'm doing all this to see if it works correctly.
But the only thing I'm getting in the output is : Player1 DayCareWorker
Even if I take the values out of the tables.
How do I make the correct if statement run when it's suppose to. This is all in a script, but should I put it in a local script?
Basically, if you have use an or statement with a conditional statement, it will check if both values are nil, and if they are, the code after doesn't run. For example,
local x = "y" if x == "x" or x == "y" then print("X = x or y ") end --------------------- OUTPUT, X = x or y
So let's use the ~= operation. This checks if something is not something, as you probably know.
local x = "y" if x ~= "x" or x ~= "y" then print("X = x or y ") end
The output would ALWAYS be the same, no matter the value of x. I hope you understand why.
Use an else statement.
So if the first conditional returns false, the second knows, and can interpret the information.
Admins = {} -- Up to 3 Admins Children = {} -- Do not touch function Children(player) -- This will turn everyone who isn't part of the list into children local Player = player:GetFullName() print(player) if Player.UserID == Admins[1] or Player.UserID == Admins[2] or Player.UserID == Admins[3] then print("DayCareWorker") else print("Child") end end game.Players.PlayerAdded:connect(Children)
There, now onto the
You're trying to access the UserId of the String, the player's name, not the player. Also, I'm not sure but I think it's userId, not UserID. That part probably doesn't matter, but I'm changing it anyways,
Admins = {} -- Up to 3 Admins Children = {} -- Do not touch function Children(Player) -- This will turn everyone who isn't part of the list into children if Player.userId == Admins[1] or Player.userId == Admins[2] or Player.userId == Admins[3] then print("DayCareWorker") else print("Child") end end game.Players.PlayerAdded:connect(Children)
I don't think this is your script, but who ever you stole/took it from, sucks at scripting. I'm removing the Children variable because it has no point. Yes, I'm touching it.
Admins = {} -- Up to 3 Admins-- Which is stupid function Children(Player) if Player.userId == Admins[1] or Player.userId == Admins[2] or Player.userId == Admins[3] then print("DayCareWorker") else print("Child") end end game.Players.PlayerAdded:connect(Children)
Final Note,
I would recommend you use a loop to check if people are on the list of being an admin, because you can add as many people as you want and it would be much better overall. Also, your name is always Player/Player1 when you're testing in studio.
Good Luck!
you used the same if twice.. It runs the same thing