Help with accessory item equiping

I have a question about this script, I’m trying to equip an accessory to a character when a tool is activated. Then I want to remove the accessory and reduce the player’s health when the tool is activated again. I’m not sure why, but the warning that says “AduriteCrownAccessory not found in ServerStorage” keeps happening in the output. I have the crown in server storage and I have the name as AduriteCrownAccessory. Can someone explain to me whats going on? This is the script

local Tool = script.Parent
local equipped = false

local function equipAccessory()
   local character = Tool.Parent
   local humanoid = character:FindFirstChildOfClass("Humanoid")
   if humanoid then
   	local AduriteCrownAccessory = game.ServerStorage:FindFirstChild("AduriteCrownAccessory")
   	if AduriteCrownAccessory then
   		local clone = AduriteCrownAccessory:Clone()
   		clone.Parent = character
   		humanoid.Health = humanoid.Health + 30
   		print("Equipped Adurite Crown and added 30 HP.")
   	else
   		warn("AduriteCrownAccessory not found in ServerStorage.")
   	end
   end
end

local function unequipAccessory()
   local character = Tool.Parent
   local humanoid = character:FindFirstChildOfClass("Humanoid")
   if humanoid then
   	local accessory = character:FindFirstChild("AduriteCrownAccessory")
   	if accessory then
   		accessory:Destroy()
   		humanoid.Health = humanoid.Health - 30
   		print("Unequipped Adurite Crown and removed 30 HP.")
   	end
   end
end

Tool.Activated:Connect(function()
   if equipped then
   	unequipAccessory()
   else
   	equipAccessory()
   end
   equipped = not equipped
end)

1 Like

Did you forget ::FindFirstChild()? It should be game.ServerStorage:FindFirstChild("AduriteCrownAccessory")

2 Likes

ok, i’ll try that and see if it works.

1 Like

I already had findfirstchild, It didn’t appear in the text for whatever reason

1 Like

Is this a LocalScript? Locals scripts cannot see anything in ServerStorage.

1 Like

IT WORKED! thank you so much man!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.