Character hat randomization upon death

  1. What do you want to achieve? Keep it simple and clear!
    Trying to make a system where on death you equip a randomized hat from a folder
  2. What is the issue? Include screenshots / videos if possible!
    Getting the hat to parent under the character doesn’t work.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried to use :AddAccessory and parenting normally along with using .CharacterAdded. Every time it produces the same result (printing works, no hat)

local Players = game:GetService('Players')
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')

local RepStorage = game:GetService("ReplicatedStorage")
local Accessories = RepStorage.Accessories

local hats = Accessories.team1.Hats:GetChildren()

local function gethats()
	local hat = hats[math.random(1, #hats)]	
	local newhat = hat:Clone()
	newhat.Parent = Character
end

local function HumanoidDied()
	print(('Player %s died!'):format(Player.Name))
	gethats()
end


Humanoid.Died:Connect(HumanoidDied)

Well, from the script you’ve sent, the hat is added to the player when it dies, but when a player dies, all joints in the character are broken, you could try disabling BreakJointsOnDeath property inside of Humanoid and work from there or create new joints and attach your hats that way.

Instead of random hats on death, do random hats when character is added

1 Like

Why are you trying to add an accessory on the character when they are dead?
Simply wait until they are respawned.

Trying that, it still has the same issue as I stated above