So i'm making a frame that hides the game from people unless their on the list (I know I could just do friends only but I have a lot of friends)
and so if their on the list then the gui gets hidden else make it shown
heres the script
print'Player Kicker' admins={"ProjectRosploit","AlexTheOtaku","Lisforlucas","Ray5069"} -- admin table game.Players.PlayerAdded:connect(function(playa) function tableContains(t, value) -- function to check for player for _, v in pairs(t) do if v == value then return true end end return false if playa and TableContains(admins, player.Name) then -- statement gets an error -- don't know what to put here end end end)
The parameter for your PlayerAdded
event was playa, then you called the TableContains
function using player.
player isn't defined! You have to call the TableContains function with playa.
But, you also called the TableContains function inside of itself, before closing the function with an end
statement.
local admins = {"ProjectRosploit","AlexTheOtaku","Lisforlucas","Ray5069"} function tableContains(t, value) for _, v in pairs(t) do if v == value then return true end end return false end game.Players.PlayerAdded:connect(function(playa) if playa and TableContains(admins, playa.Name) then --Your Code end end)
Make the table, a dictionary with players' names! That way you can index the table like admins[playa.Name]
to see if the player is there, and you can eradicate the whole tableContains
function completely.
local admins = { ["ProjectRosploit"] = true, ["AlexTheOtaku"] = true, ["Lisforlucas"] = true, ["Ray5069"] = true } game.Players.PlayerAdded:connect(function(playa) if admins[playa.Name] then --Your Code end end)
Your statement returns an error because player
in player.Name
is not defined. You probably meant playa.Name
.
Also, format your code in an organized manner!
print'Player Kicker' admins = {"ProjectRosploit","AlexTheOtaku","Lisforlucas","Ray5069"} game.Players.PlayerAdded:connect(function(playa) function tableContains(t, value) for _, v in pairs(t) do if v == value then return true end end return false if playa and TableContains(admins, playa.Name) then end end end)
The issue seems to be located in the function itself.
The function is not called outside of its scope.
The "if" is in the wrong place.
Let's make the function a static one.
print'Player Kicker' admins = {"ProjectRosploit","AlexTheOtaku","Lisforlucas","Ray5069"} function tableContains(t, value) for _, v in pairs(t) do if v == value then return true end end return false end game.Players.PlayerAdded:connect(function(playa) if playa and TableContains(admins, playa.Name) then end end)
Now we're getting somewhere!
Now, for your GUI, I assume it's already in game.StarterGui
. So, let's define it.
print'Player Kicker' admins = {"ProjectRosploit","AlexTheOtaku","Lisforlucas","Ray5069"} function tableContains(t, value) for _, v in pairs(t) do if v == value then return true end end return false end game.Players.PlayerAdded:connect(function(playa) if playa then local PlayerGui = playa:WaitForChild("PlayerGui") local Gui = PlayerGui:WaitForChild("ScreenGui") -- Or however you want to name it. local Frame = Gui:WaitForChild("Frame") if TableContains(admins, playa.Name) then Frame.Visible = false else Frame.Visible = true end end end)
Since game.StarterGui
replicates its children to the Player's PlayerGui, the GUIs will be visible to the people in the list. So let's wrap the "if" statement with a .CharacterAdded event.
print'Player Kicker' admins = {"ProjectRosploit","AlexTheOtaku","Lisforlucas","Ray5069"} function tableContains(t, value) for _, v in pairs(t) do if v == value then return true end end return false end game.Players.PlayerAdded:connect(function(playa) playa.CharacterAdded:connect(function(Character) -- In this case, you don't need to see if the "playa" exists. local PlayerGui = playa:WaitForChild("PlayerGui") local Gui = PlayerGui:WaitForChild("ScreenGui") -- Or however you want to name it. local Frame = Gui:WaitForChild("Frame") if TableContains(admins, playa.Name) then Frame.Visible = false else Frame.Visible = true end end) end)
If you want it so that if you want to "Ban" or kick people out of your game so people don't join, use a table, and use the Kick method.
It kicks the player, if you add a string in between the "()"s then you can add a custom message
game:GetService("Players").Player1:Kick("You have been kicked from the server!")
local message = "You are not allowed in this game." --Add a message here allowed = {"ProjectRosploit","AlexTheOtaku","Lisforlucas","Ray5069"} game:GetService("Players").PlayerAdded:connect(function(plyr) local IsAllowed = false for _,allow in pairs(allowed) do if plyr.Name == allow then IsAllowed = true end end if not IsAllowed then plyr:Kick(message) end end)
Hope it helps!