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
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
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.