Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make pets move around player ?

Asked by 4 years ago

I mean the player is the center of the circle and the pet will move in a circle. This is my script, pets only follow behind the player

local char = script.Parent.Parent.Parent
local hum = char:FindFirstChild("Humanoid")
local rig = char.Humanoid.RigType
local torso = char:FindFirstChild("Head")
local pet = script.Parent
local maxFloat = 1
local floatInc = 0.025
local sw = false
local fl = 0
while true do
    wait()
    local random = math.random(1,15)
    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-random,2+fl,3)
            pet.BodyPosition.Position = Vector3.new(cf.x,cf.y,cf.z)
            pet.BodyGyro.CFrame = torso.CFrame * CFrame.new(3,0,-3)
        else
            break
        end
    end
end

Answer this question