Alright so. I am making a script that removes a player’s hats and adds a hat based on their rank in a group. It works, but once they respawn it only removes the hats and then says that the hats do not exist in ServerStorage. This leads me to believe that it isn’t cloning them but it is just changing their parent to the player’s head, but I’m not 100% sure because this is the first time I’ve worked with :AddAccessory(). If anyone knows how I can fix this please let me know, as I’ve tried two different ways so far, which are as follows;
-
Cloning the hat before using
:AddAccessory()to make it so the hat is still inServerStorage, which still only worked the first time and then errored saying the hat does not exist. -
I tried using
:Clone()to clone it into the player’s head, which worked, but the hat was not attached to the player and I saw it spawn far off in the distance where it’s origin position is. So it did in fact clone, but it failed to attach to the player’s head. -
I tried cloning it and then using
Instance.New("WeldConstraint")to weld it to the head but that also failed.
I will include the script and hierarchy below, and any help is welcome.
local hats = game.ServerStorage.Hats -- Folder location
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
player.CharacterAppearanceLoaded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid:RemoveAccessories()
if player:IsInGroup(15038816) then
hats.HQ:Clone().Parent = player.PlayerScripts
elseif player:IsInGroup(15177154) then
if player:GetRankInGroup(15177154) < 100 then
humanoid:AddAccessory(hats.RMP_LR)
elseif player:GetRankInGroup(15177154) >= 100 then
humanoid:AddAccessory(hats.RMP_HR)
end
elseif player:IsInGroup(15040213) then
if player:GetRankInGroup(15040213) < 100 then
humanoid:AddAccessory(hats.IR_LR)
elseif player:GetRankInGroup(15040213) >= 100 then
humanoid:AddAccessory(hats.IR_HR)
end
elseif player:IsInGroup(15444520) then
if player:GetRankInGroup(15444520) < 100 then
humanoid:AddAccessory(hats.RGG_LR)
elseif player:GetRankInGroup(15444520) >= 100 then
humanoid:AddAccessory(hats.RGG_HR)
end
end
end)
end)
end)

(Just in case you’re wondering, yes the hats are set up properly, if I put them in StarterCharacterScripts it works and like I said it works correctly the first time)