You are accessing the Humanoid of your character before it exists. You could use :WaitForChild, :FindFirstChild, or .CharacterAdded. Further, since you're using PlayerAdded, your function should only deal with the player that was added (not all the players in the game), since it'll be called for each player.
_G.Whitelist = {"Dusk_Reality", "Roblox"}
local isAdministrator = {}
for i = 1, #_G.Whitelist do
isAdministrator[_G.Whitelist[i]] = true
end
game.Players.PlayerAdded:Connect(function(player)
if isAdministrator[player.Name] then
print(player, "has joined and is an administrator")
else
print(player, "has joined")
return
end
player.CharacterAdded:Connect(function(char)
wait()
char.Humanoid.Health = 0
end)
player.Chatted:Connect(function(msg)
end)
end)
I tested the code in a Script in ServerScriptService. Note that if you put this code in a LocalScript or accidentally set Enabled to false, the script would not run.
Also, if more than one script needs to know the list of administrators, it is better to use a ModuleScript rather than to rely on _G -- that way you can require the list of administrators rather than having to wait for _G.Whitelist to be defined (in case the script that creates the Whitelist runs after the script that needs the list).
1 comment
Also if you are thinking that I join after the loop finishes that is not the case because the print("This does not print") doesn't print and that is what comes first so yeah.