About
Hey there, i have this halo script which when you buy it as a gamepass allows you to wear the halo hat. However when you reset your character the hat goes away. I want it to stay even after you reset your char however i dont really know how to go about this. Any Help Can Be Appreciated.
Code For Equip Script :

1 Like
Have it seat up so when you die, it goes through all you accessories via Humanoid:GetAccessories()
and store the first instance of an accessory that has the word Halo
via string.match(accessoryName, "Halo")
or string.find
into a dictionary. And when the character respawns, try to see if they have a stored halo, and if they do, get the halo from where they are stored via the name and AddAccessory
Something like this would be an example of how you could do it
local serviceStorage = game:GetService("ServerStorage")
local equippedHalos = {}
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
local found = equippedHalos[plr.Name]
if found then
hum:AddAccessory(serviceStorage[found]:Clone())
equippedHalos[plr.Name] = nil
end
hum.Died:Connect(function()
for _,halo in pairs(hum:GetAccessories()) do
if not string.find(halo.Name, "Halo") then continue end
equippedHalos[plr.Name] = halo.Name
break
end
end)
end)
end)
This will not work if the player died by reaching the FallenPartsDestroyHeight
, as that destroys your character so it wont be able to find the halo, you will need to make a check that kills you just before you reach that height, depending on your respawn time
3 Likes
Hey, uhm thanks it worked very well lmao, tho i changed WaitForChildOfClass To WaitForChild Since it gave me an error, can you tell me what the use and difference of waitforchild and waitforchildofclass is?
Thanks
1 Like
Oh wait my bad, I was accidentally confusing it with FindFirstChildOfClass
, that was a mistake on my end! WaitForChildOfClass
doesn’t exist yet!
No Problem!
Btw for the player dying by falling and dying can you elaborate on that please,thanks!
Basically when you go below the FallenPartsDestroyHeight
, your character will be destroyed instead of breaking apart like normal. Because of this, the game will not be able to get the equipped Halo.
What I did was have it a RunService.Heartbeat
event set up so every frame, it compares your height with the FallenPartsDestroyHeight property of the workspace and you’re around 50 studs before reaching it, it kills you instead. This can only really work if your respawn time is 0
, if you have a higher time, you will need to change it up a bit.
I put a localscript like this in StarterCharacterScripts
local runService = game:GetService("RunService")
local destroyHeight = -workspace.FallenPartsDestroyHeight
local char = script.Parent
local root = char:WaitForChild("HumanoidRootPart")
runService.Heartbeat:Connect(function()
if (destroyHeight - root.Position.Y) <= 50 then
char.Humanoid.Health = 0
end
end)
Not exactly sure if this is exactly how I did it, but it shows a way you could do it
1 Like