✓ Accepted answer
Flaws with your script:
-Your first and foremost flaw: You defined "isMod" outside of the PlayerAdded() event. That means that it's changed whenever a mod enters the game, and every player after will be considered a mod whether they are or not.
-You can't use plr:WaitForChild("Character") because the character is not a child of the player. We can use a while loop or the CharacterAdded() event, though a while loop is better to use further down in the code, since if we use CharacterAdded(), it might not pick up on the character spawning the first time depending on how long it takes the previous code to run.
-The test name for the player has two interchangeable names: "Player" and "Player1". Not sure
why, but you still have to compensate for it. We can fix this by putting both names in the table.
-You have the if statement inside of the for loop. That means that for each iteration through the table, if the mod is not a player, then it will print "A player has entered "..GameName.."!". We can fix this by using a variable that is true if the player is a mod, and use it to create an if statement that prints a mod has entered, otherwise a player has entered.
-Additionally, I'm assuming you want to clone the part into a moderator's character whenever he/she spawns instead of just once. For this, we can use the Character Added event.
I went ahead and made a script in super-safe mode, so you can use it with no risk.
Finished Script:
local Mods = {"LegendaryArmor","alphawolvess","Player","Player1","aquathorn321"}
local GameName = "FlobbyGames"
game.Players.PlayerAdded:connect(function(plr)
local b = false
local player = false
local m
m = plr.CharacterAdded:connect(function(character)
while not (b or player) do
wait()
end
if player then m:disconnect()
else
local Copy = game.ReplicatedStorage.Moderators:Clone()
Copy.Parent = character.Head
end
end)
for i,Mod in pairs(Mods) do
if plr.Name:lower() == Mod:lower() then
b = true
break
end
end
while not plr.Character do
wait()
end
if b then
print("A moderator has entered "..GameName.."!")
else
print("A player has entered "..GameName.."!")
player = true
end
end)
1 comment
Use CharacterAdded instead of plr:WaitForChild.