It is kind of difficult to write it in a sentence for people to understand. Recently I have been trying to make a script in which anyone who isn't in a designed whitelist will have a NPC target them down, which will cause them to get kicked on touch. It worked, but when they rejoin or another person joins. The NPC does not spawn in. Sort of need some help in regards to this.
Here is the script I had trouble on
--Whitelist script by fridayboycool : Modified by XenilMatrix [HUGE CREDITS TO OWNER]
local whitelisted = {
["XenilMatrix"] = true;
[""] = true;
["Player1"] = true;
}
local player = script.Parent.Parent
local teams = game.Teams
--------------------------------------------------------------------------------------------------------------------
while true do
wait(0.01)
if whitelisted[player.Name] then
else -- 2020/3/31 Got it working but failure to repeat again when another invalid person joins the game, but they are not listed.
while true do
wait(0.001)
if #teams.Players:GetPlayers() > 0 then
local Object = game.ReplicatedStorage["NPC"]:Clone()
Object.Parent = game.Workspace
Object.Position = Vector3.new()
Object:MoveTo(Vector3.new(0,0,0))
wait(0.001)
end
end
end
end

5 comments
In this script, I utilized the player added event, which is more efficient than constantly checking if there are more than 0 players. I check if the player that joined isn't in the whitelist, if that person isn't, then I copy the npc. I also made it so if that player isn't there anymore, then the npc is removed. NOTE: IF THERE ARE TWO OR MORE NON WHITELISTED PPL THIS MIGHT BREAK.
Is there anyway to fix that problem, in regards to the script breaking when there are more unlisted ppl?
let me edit
You have to edit lines 17 and 20 in order for your NPC to move and be positioned
I acknowledge that, I already got a NPC already made. It does move and I believe it is positioned.