Reset Character

local function LoadChicken(plr: Player, reason: string)
    plr.CharacterAdded:Wait()
    local ChickenClone = ServerStorage.Chickens["Default Chicken"]:Clone()
    ChickenClone.Name = plr.Name
    plr.Character:Destroy()
    plr.Character = ChickenClone
    ChickenClone.Parent = workspace
    local Animate = plr.Character:WaitForChild("Animate")
    Animate.Disabled = false
end
function ChickenService:Start()
    Players.PlayerAdded:Connect(function(plr) 
        LoadChicken(plr)
    end)
end

How do I make this do the same thing after the player dies? I tried characteradded event and human died, nothing works.

is the code run in the server?

Yes, it is running in the server.

you could run this in a while loop

local function LoadChicken(plr: Player, reason: string)
    while(wait()) do
        plr.CharacterAdded:Wait()
        local ChickenClone = ServerStorage.Chickens["Default Chicken"]:Clone()
        ChickenClone.Name = plr.Name
        plr.Character:Destroy()
        plr.Character = ChickenClone
        ChickenClone.Parent = workspace
        local Animate = plr.Character:WaitForChild("Animate")
        Animate.Disabled = false
    end;
end
function ChickenService:Start()
    Players.PlayerAdded:Connect(function(plr) 
        LoadChicken(plr)
    end)
end
local function LoadChicken(plr: Player, reason: string)
    local ChickenClone = ServerStorage.Chickens["Default Chicken"]:Clone()
    ChickenClone.Name = plr.Name
    plr.Character:Destroy()
    plr.Character = ChickenClone
    ChickenClone.Parent = workspace
    local Animate = plr.Character:WaitForChild("Animate")
    Animate.Disabled = false
end
function ChickenService:Start()
    Players.PlayerAdded:Connect(function(plr) 
       plr.CharacterAdded:Connect(function(char)
               LoadChicken(plr)
       end
    end)
end

you can add the charaterAdded event after the playeraddded so it will fire when the character joins the game and when the character respawns.

Nevermind, it works ty :smiley:

local function LoadChicken(plr: Player, reason: string)
    plr.CharacterAdded:Wait()
    local ChickenClone = ServerStorage.Chickens["Default Chicken"]:Clone()
    ChickenClone.Name = plr.Name
    plr.Character:Destroy()
    plr.Character = ChickenClone
    ChickenClone.Parent = workspace
    local Animate = plr.Character:WaitForChild("Animate")
    Animate.Disabled = false
end
function ChickenService:Start(plr)
   LoadChicken(plr)
end

game.Players.PlayerAdded:Connect(function(p)
    p.CharacterAdded:Connect(function(c)
        ChickenService:Start(plr)
    end)
end)

I would try this.

local function LoadChicken(player, reason)
	local ChickenClone = ServerStorage.Chickens["Default Chicken"]:Clone()
	ChickenClone.Name = player.Name
	player.Character:Destroy()
	player.Character = ChickenClone
	ChickenClone.Parent = workspace
	local Animate = player.Character:WaitForChild("Animate")
	Animate.Disabled = false
end


Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(char)
		LoadChicken(player, "idk")
	end)
end)

I changed some of the variables to make it easier to work with but it shouldn’t be hard to change them back/. But, the main thing I changed was taking the LoadChicken out of the function and replacing it with CharacterAppearanceLoaded. This just makes it so that every time you respawn/spawn in, it will run the function.