When the player named "DAHUI84" enters the game, then it is automatically kicked, while the player named "NiniBlackJackQc" enters without problem. But i want both names to work, Can you help me?
local Authorization = {"NiniBlackJackQc","DAHUI84"} local player = game:GetService("Players").LocalPlayer repeat wait() until player.Character local Character = player.Character for i, v in pairs(Authorization) do if player.Name == v or player.UserId == game.CreatorId then script.Parent:Destroy() GameSound() print("Administrator: "..player.Name, "Administrator Id: "..player.UserId) return; -- This stops the loop from running anymore. else Character:Destroy() Instance.new("BlurEffect",workspace.CurrentCamera) IntroSound() print("Player: "..player.Name, "Player Id: "..player.UserId) return; end end
Let's "unroll" the for
loop. For loops just do something once per thing in the container. So your code is currently equivalent to
do -- iteration 1 local v = "NiniBlackJackQc" if player.Name == v or player.UserId == game.CreatorId then script.Parent:Destroy() GameSound() print("Administrator: "..player.Name, "Administrator Id: "..player.UserId) return; -- This stops the loop from running anymore. else Character:Destroy() Instance.new("BlurEffect",workspace.CurrentCamera) IntroSound() print("Player: "..player.Name, "Player Id: "..player.UserId) return; end end do -- iteration 2 local v = "DAHUI84" if player.Name == v or player.UserId == game.CreatorId then script.Parent:Destroy() GameSound() print("Administrator: "..player.Name, "Administrator Id: "..player.UserId) return; -- This stops the loop from running anymore. else Character:Destroy() Instance.new("BlurEffect",workspace.CurrentCamera) IntroSound() print("Player: "..player.Name, "Player Id: "..player.UserId) return; end end
Notice that you're never going to get passed the first loop: you unconditionally return
having made a decision based on only the first name in the list.
Here is the code you meant to write. We can define isAuthorized
later:
local Authorization = {"NiniBlackJackQc","DAHUI84"} local player = game:GetService("Players").LocalPlayer repeat wait() until player.Character local Character = player.Character if isAuthorized() then script.Parent:Destroy() GameSound() print("Administrator: "..player.Name, "Administrator Id: "..player.UserId) else Character:Destroy() Instance.new("BlurEffect",workspace.CurrentCamera) IntroSound() print("Player: "..player.Name, "Player Id: "..player.UserId) end
This clearly doesn't have logic bugs, because it says to do exactly what you want (notice that since there's no more code there's no need for return
s either)
isAuthorized
is simple:
function isAuthorized() if player.UserId == game.CreatorId then return true end for _, name in pairs(Authorization) do if name == player.Name then return true end -- we can't say "else" because there are more names end end
I'm not an expert at scripting but I would try to change player to players because it is more than 1 player or I will try to make 2 separate script and make it with 1 of the names each instead of 2 times in one script. Hope I helped :) Merry Christmas!