Save Equip So When You Reset Its Still On Head

I make script that when you equip it will clone on you head but when i reset i need to equip it again its annoying…

Replicated Storage Script :
Untitled

local Player = game.Players

local repStorage = game:GetService("ReplicatedStorage")

local remotes = repStorage.HaloRemotes.BlackHalo

local equip = remotes.Equip

local hat = game.ServerStorage.Black

equip.OnServerEvent:Connect(function(player)

local character = player.Character

local humanoid = character.Humanoid

local clone = hat:Clone()

humanoid:AddAccessory(clone)

if character:FindFirstChild("BlackHalo") then

character.BlackHalo:Destroy()

end

end)

Button When You Equip : Starter Gui

local equipped = script.Parent.Parent.Equipped

local unequipped = script.Parent.Parent.Unequipped

script.Parent.MouseButton1Click:Connect(function()

game.ReplicatedStorage.HaloRemotes.BlackHalo.Equip:FireServer()

unequipped.Visible = true

equipped.Visible = true

end)

Add a .Died event on the player’s Humanoid so when they die, the accessory they’re wearing is stored into a table so when they respawn and they have an accessory with a specific name, readd it to their player. I did something similar to this a while ago. What did was this

  • When the character was added, check if they have a key with their name in the table
  • If they do, get the accessory from a folder where they are kept with the name of what is stored with the key and set the key’s value to nil
  • Connect it so when you die, it goes through your accessories and if it finds one with a specific keyword in it, set it as the value to connect with your key in the dictionary

Here’s an example of how you could do it (copying and pasting it will not work, you have to change it around to match your code)

local equipTable = {}

Player.CharacterAdded:Connect(function(char)
	local haloName = equipTable[char.Name]
	local hum = char.Humanoid

	if haloName then
		hum:AddAccessory(game.ServerStorage.Halos[haloName]:Clone())
		equipTable[char.Name] = nil
	end
	
	hum.Died:Connect(function()
		for _,halo in pairs(hum:GetAccessories()) do
			if not string.find(halo.Name, "Halo") then continue end
			equipTable[char.Name] = halo.Name
			break
		end
	end)
end)

Note: This assumes you have a folder in ServerStorage where you keep your halos in this case called “Halos”, and it assumes that the keyword in each halo is “Halo”

I’m not sure if there is a better way as this is how I did it

1 Like

Doesn’t work i’ve tried modifying it.