I’m trying to make a script that sets the players clothing and when the player dies it sets the players clothing again but the code I made doesn’t work
code:
game.Players.PlayerAdded:Connect(function(player)
--Variables
local shirtclone = game.ServerStorage.Clothing.Shirt:Clone()
local pantsclone = game.ServerStorage.Clothing.Pants:Clone()
local hatclone = game.ServerStorage.Clothing.Hat:Clone()
-- Wait for the character to be loaded
while not player.Character do task.wait() end
local char = player.Character
if char then
shirtclone.Parent = char
pantsclone.Parent = char
hatclone.Parent = char
print("Set Clothing")
end
local humanoid = char:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
local newChar = player.Character
while not newChar do task.wait() end
local newShirt = shirtclone:Clone()
local newPants = pantsclone:Clone()
local newHat = hatclone:Clone()
newShirt.Parent = newChar
newPants.Parent = newChar
newHat.Parent = newChar
print("Set Clothing")
end)
player.CharacterRemoving:Connect(function(character)
local shirt = character:FindFirstChild("Shirt")
local pants = character:FindFirstChild("Pants")
local hat = character:FindFirstChild("Hat")
if shirt then shirt:Destroy() end
if pants then pants:Destroy() end
if hat then hat:Destroy() end
end)
end)
game.Players.PlayerAdded:Connect(function(player)
--Variables
local shirtclone = game.ServerStorage.Clothing.Shirt:Clone()
local pantsclone = game.ServerStorage.Clothing.Pants:Clone()
local hatclone = game.ServerStorage.Clothing.Hat:Clone()
-- Wait for the character to be loaded
while not player.Character do task.wait() end
local char = player.Character
if char then
shirtclone.Parent = char
pantsclone.Parent = char
hatclone.Parent = char
print("Set Clothing")
end
local humanoid = char:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
task.wait(1)
local newChar = player.Character
while not newChar do task.wait() end
local newShirt = shirtclone:Clone()
local newPants = pantsclone:Clone()
local newHat = hatclone:Clone()
newShirt.Parent = newChar
newPants.Parent = newChar
newHat.Parent = newChar
print("Set Clothing")
end)
end)