Hello, I’m working on a game with pets and for some reason the pets disappear when you touch it.
Script
local char = script.Parent.Parent
local pet = script.Parent
local hum = char:WaitForChild(“Humanoid”)
local torso = char:WaitForChild(“UpperTorso”)
local maxFloat = 1
local floatInc = 0.025
local sw = false
local fl = 0
while true do
wait()
if not sw then
fl = fl + floatInc
if fl >= maxFloat then
sw = true
end
else
fl = fl - floatInc
if fl <=-maxFloat then
sw = false
end
end
if pet ~= nil and hum ~= nil and torso ~= nil then
if hum.Health >= 0 then
local cf = torso.CFrame * CFrame.new(3,2+fl,3)
pet:WaitForChild(“BodyPosition”).Position = Vector3.new(cf.x,cf.y,cf.z)
pet:WaitForChild(“BodyGyro”).CFrame = torso.CFrame * CFrame.new(3,0,-3)
else
break
end
end
end