I'm still having a little trouble with tables since 2 weeks, I'm not sure if this script will work:
player = game.Players.LocalPlayer a = {36491121, 57099125, 60788697} if player.userId == #a then script.Parent.Parent:Destroy() --This is a ScreenGui end
What it's meant to do is if the player's userId is one of those in the table, the GUI permanently gets removed from his StarterGui.
You've misunderstood tables a little bit.
The #
means "length." So, #a
is just going to be 3
. With that in mind, your read reads:
player = game.Players.LocalPlayer a = {36491121, 57099125, 60788697} if player.userId == 3 then script.Parent.Parent:Destroy() --This is a ScreenGui end
Naturally you aren't trying to check whether their player ID is 3
. So here's what you can do instead: iterate through the table.
Start with setup:
player = game.Players.LocalPlayer a = {36491121, 57099125, 60788697}
Next, we need some way to tell whether they are in the list.
areTheyInTheList = false
It starts false
, because we haven't found them in the list yet.
Now, we will look through the list:
for i = 1, #a do
What this means is that i
will first be 1
, then be 2
, then be 3
, and stop at that point, since #a
= 3
.
Inside this list, we need to look at a[i]
and check it. So:
if a[i] == player.userId then areTheyInTheList = true end
Once we find it, we set it to true. Then, end the loop:
end
And now we act on it:
if areTheyInTheList then player:Kick() end
All together, our script is:
player = game.Players.LocalPlayer a = {36491121, 57099125, 60788697} areTheyInTheList = false for i = 1, #a do if a[i] == player.userId then areTheyInTheList = true end end if areTheyInTheList then player:Kick() end
a = {36491121, 57099125, 60788697} if player.userId == #a then script.Parent.Parent:Destroy() end
I can see several things wrong with this script that would break it entirely. Where did you define player? IS the script.Parent.Parent the player? You need to use a loop to go through that table. Why not use the :Kick() method? Is this script in StarterPack or StarterGui?
Here's my modified version of your script;
--THIS MUST BE IN A LOCAL SCRIPT IN STARTERGUI OR STARTERPACK! player= game.Players.LocalPlayer a = {36491121, 57099125, 60788697} for _,v in pairs(a) do if v== player.userId then player:Kick() end end