function touch(W)if W.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")and((W.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")).health>0 and not master)then master=W.Parent.Head spring=Instance.new("\083\112\114\105\110\103\067\111\110\115\116\114\097\105\110\116",pet)spring.Attachment0=pet.SpringAttach spring.Attachment1=master.HatAttachment spring.FreeLength=maxDistance spring.Stiffness=1000 spring.Damping=2 orient=Instance.new("\065\108\105\103\110\079\114\105\101\110\116\097\116\105\111\110",pet)orient.Attachment0=pet.OrientAttach orient.Attachment1=master.HatAttachment orient.RigidityEnabled=true function death()spring:Destroy()orient:Destroy()pet.CFrame=startpos master=nil end master.Parent.Humanoid.Died:Connect(death)end end pet.Touched:Connect(touch)
-- Runs when someone touches our pet
function touch(part)
	-- IF player AND not dead AND has no master
	if part.Parent:FindFirstChild("Humanoid") and part.Parent:FindFirstChild("Humanoid").health > 0 and not master then
		-- Assign the master
		master = part.Parent.Head

		--Create a new spring
		spring = Instance.new("SpringConstraint", pet)
		spring.Attachment0 = pet.SpringAttach
		spring.Attachment1 = master.HatAttachment
		spring.FreeLength = maxDistance
		spring.Stiffness = 1000
		spring.Damping = 2

		-- Makes pet turn with player
		orient = Instance.new("AlignOrientation", pet)
		orient.Attachment0 = pet.OrientAttach
		orient.Attachment1 = master.HatAttachment
		orient.RigidityEnabled = true

		-- Reset pet apon death
		function death()
			spring:Destroy()
			orient:Destroy()
			pet.CFrame = startpos
			master = nil
		end

		master.Parent.Humanoid.Died:Connect(death)
	end
end

pet.Touched:Connect(touch)
