Answered by
5 years ago Edited 5 years ago
This is because Head
wasn't found in hit.Parent
. You should instead have an if
statement that checks for it.
local debounce = true -- use local variables
local function onTouched(hit) -- here too
if hit.Parent:FindFirstChild("Head") then -- :findFirstChild is deprecated, use :FindFirstChild
local acc = Instance.new("Accessory") -- Hat is deprecated
local p = game.Workspace.pet:Clone()
p.Name = "GreenTopHat"
p.Position = hit.Parent.Head.Position -- this only runs if head was found !!
p.Name = "Handle"
p.Locked = true
p.Parent = hit.Parent
h.AttachmentPos = Vector3.new(0,0,1)
h.Parent = hit.Parent
end
end
script.Parent.Touched:Connect(onTouched) -- :connect is deprecated, use:Connect