I wrote a script that detects when a player spawns, and then (if they're a zombie in the context of my game) gives them clothes and puts them in the map. For some reason, players spawn with millions of shirts and pants and hats and that's not at all what I want. How can I make it so players spawn with only 1 outfit? Here's what the root looks like: https://imgur.com/a/vgrLv3o
local Players = game:GetService("Players")
local function onCharacterAdded(character)
Player = game.Players:GetPlayerFromCharacter(character)
wait(0.5)
if Player.PlayerParameters.HumanOrZombie.Value == 0 then
-- no spawn required
elseif Player.PlayerParameters.HumanOrZombie.Value == 1 then
-- human!
wait(0.5)
survivorspawns = workspace:WaitForChild("SurvivorSpawns"):GetChildren()
randomspawn = survivorspawns[math.random(1, #survivorspawns)]
character:MoveTo(randomspawn.Position)
elseif Player.PlayerParameters.HumanOrZombie.Value == 2 then
-- zombie!
for i,v in pairs(character:GetChildren()) do
if v:IsA("Accessory") then
v:Destroy()
elseif v:IsA("BasePart") then
v.BrickColor = BrickColor.new("Dark green")
elseif v:IsA("Shirt") then
v:Destroy()
elseif v:IsA("Pants") then
v:Destroy()
elseif v:IsA("ShirtGraphic") then
v:Destroy()
end
if game.ReplicatedStorage.MapName.Value == "Grassy Plains" then
randomclothes = game.ServerStorage.ZombieClothes.GrassyPlains:GetChildren()
pickedclothes = randomclothes[math.random(1, #randomclothes)]
for i,x in pairs(pickedclothes:GetChildren()) do
x:Clone().Parent = character
end
end
end
wait(0.5)
zombiespawns = workspace:WaitForChild("ZombieSpawns"):GetChildren()
randomspawnn = zombiespawns[math.random(1, #zombiespawns)]
character:MoveTo(randomspawnn.Position)
end
if game.ReplicatedStorage.RoundBeginning.Value == true then
character.Humanoid.WalkSpeed = 0
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

2 comments
Thank you! I didn't really know that it was a loop, I thought it was just some function
No problem, glad I could help!