Keep getting the error: attempt to index nil with 'Equipped' with morph

i am making a morph and i need the morph pad to give a tool whenever it is touched. however,i always get the error: 17:54:26.623 Players.YTFalloutDoomy.Backpack.ClassicSword.MouseIcon:27: attempt to index nil with ‘Equipped’ - Studio

here’s the script:

local item = game:GetService("ServerStorage"):WaitForChild("ClassicSword")
local db = true


script.Parent.Touched:connect(function(part)
 if part.Parent:FindFirstChild("Humanoid") ~= nil then
  local player = game.Players:GetPlayerFromCharacter(part.Parent)
  if player ~= nil then
   if player.Backpack ~= nil then
    if db == true then
     db = false
     item:Clone().Parent = player.Backpack
     wait(5)
     db = true
    end
   end
  end
 end
end)

i couldn’t find any solutions to this. the script is a server-side script and it’s located in the morph pad. the tool is located in server storage.

edit: found a possible fix, the morph pad will not give the tools but other parts can. what i did is: when the player touches the pad,he gets teleported for 1 second on the pad that gives tools,then the pad disappears and the player gets teleported back.

although this is a fix,it’s not really good and i would still like some help. if this piece of info can help:

it’s an RTHRO morph
it was an old NPC i created,and to make it a morph i just removed the AI from it
to make the rig i got an rthro rig and just replaced the meshes.

1 Like

The error lies inside the sword itself. Can you send the code of the LocalScript called MouseIcon inside ClassicSword?

Mouse_Icon = "rbxasset://textures/GunCursor.png"
Reloading_Icon = "rbxasset://textures/GunWaitCursor.png"

Tool = script.Parent

Mouse = nil

function UpdateIcon()
	if Mouse then
		Mouse.Icon = Tool.Enabled and Mouse_Icon or Reloading_Icon
	end
end

function OnEquipped(ToolMouse)
	Mouse = ToolMouse
	UpdateIcon()
end

function OnChanged(Property)
	if Property == "Enabled" then
		UpdateIcon()
	end
end

Tool.Equipped:Connect(OnEquipped)
Tool.Changed:Connect(OnChanged)

i also wanna point out that it does give me the tool when im not morphed