Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i make a script that only shows to particular userids? (GUI)

Asked by 3 years ago
Edited 3 years ago

i am trying to make a Ban Screen but my code does not work why? the banscreen is just an gui with text on it

My code:

local Banned_Screen = script.Parent.Parent.Banned_Screen
local Plr = game.Players.LocalPlayer

Banned_user_Id = {539909602,395397082} --Two userid does not work but one userid does 


for i,v in pairs(Banned_user_Id) do
    if game.Players.LocalPlayer.UserId == v then
        Banned_Screen.Visible = true

    else
        Banned_Screen.Visible = false
end
end

2 answers

Log in to vote
0
Answered by
I_Nev 200 Moderation Voter
3 years ago

Simple mistake, what was happening was the code would work correctly, but not how you'd want. So what was happening was it would check the first id and it would be true and make the gui visible, but it would check the second next and it would be false so it would reset it back to nonvisible, we can add a break into loops to make it stop after getting a specific answer like so:

local Banned_Screen = script.Parent.Parent.Banned_Screen
local Plr = game.Players.LocalPlayer

Banned_user_Id = {539909602,395397082} --Two userid does not work but one userid does 


for i,v in pairs(Banned_user_Id) do
    if game.Players.LocalPlayer.UserId == v then
        Banned_Screen.Visible = true
        break
    else
        Banned_Screen.Visible = false
    end
end

Let me know if this helps

0
Thankyou so much @I_Nev Retallack445 75 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Don't check the Id's, check the names.

01  local Banned_Screen = script.Parent.Parent.Banned_Screen
02  local Plr = game.Players.LocalPlayer
03   
04  Banned_user = {Patrick, George} --Put the names of each banned player.
05   
06   
07  for i,v in pairs(Banned_user_Id) do
08      if game.Players.LocalPlayer.Name == v then
09          Banned_Screen.Visible = true
11      else
12          Banned_Screen.Visible = false
13  end
14  end

Also give us more details of what isn't working. I'm gonna give you some tips. Always check the output and if you have, fix them. And also if it isn't working without errors, put some Print() after each function/event to see if it's working. Another TIP is to know the location of the LocalScript, because you can't insert a LocalScript in SSS for example. This code should go in StarterPlayerScripts.

0
Names can be changed but ids cant Retallack445 75 — 3y
0
True LetalNightmare 99 — 3y

Answer this question