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

im making a pet system but i have a problem with the pet follow?

Asked by 3 years ago

the pet orientation when the player walks isnt on the side of the player walks how i fix that (there are multiple pets aorund the players)

script:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local playerPets = workspace.Player_Pets
local runS = game:GetService("RunService")
local TweenS = game:GetService("TweenService")
local petHandler = game.ReplicatedStorage.Module.PetHandler

function GetRadiusSize(amount)
    amount = tonumber(amount) or 0

    local Interval = 0.5
    if amount <= 1 then
        Interval = 5
    elseif amount <= 2 then
        Interval = 3
    elseif amount <= 3 then
        Interval = 2
    elseif amount <= 4 then
        Interval = 1.65
    elseif amount <= 8 then
        Interval = 1.25
    elseif amount <= 12 then
        Interval = 1.1
    elseif amount <= 16 then
        Interval = 0.9
    end

    local Add = Interval * amount
    return (-Add)
end

repeat wait() until playerPets:FindFirstChild(plr.Name)

runS.RenderStepped:Connect(function()
    local char = plr.Character or plr.CharacterAdded:Wait()
    if char.Humanoid.MoveDirection.Magnitude > 0 then
        local index, maxIndex = 0, 0
        for pet, petTable in pairs(playerPets[plr.Name]:GetChildren()) do
            maxIndex = maxIndex + 1
        end

        local radSize = GetRadiusSize(maxIndex)
        for pet, petTable in pairs(playerPets[plr.Name]:GetChildren()) do


            local cf = CFrame.fromAxisAngle(Vector3.new(0,1,0), index/maxIndex * math.pi * 2) * CFrame.new(0,0,radSize) * CFrame.Angles(0, 0 + petTable.PrimaryPart.Orientation.Y,0)

            local tween = TweenS:Create(petTable.Root, TweenInfo.new(0.3),{CFrame = char.PrimaryPart.CFrame * cf})
            tween:Play()
            index = index + 1
        end
    else
        local index, maxIndex = 0, 0
        for pet, petTable in pairs(playerPets[plr.Name]:GetChildren()) do
            maxIndex = maxIndex + 1
        end

        local radSize = GetRadiusSize(maxIndex)
        for pet, petTable in pairs(playerPets[plr.Name]:GetChildren()) do
            local cf = char.HumanoidRootPart.CFrame * CFrame.fromAxisAngle(Vector3.new(0,1,0), index/maxIndex * math.pi * 2) * CFrame.new(0,0,radSize) * CFrame.Angles(0,math.rad(180),0)

            local tween = TweenS:Create(petTable.Root, TweenInfo.new(0.3),{CFrame = cf})
            tween:Play()
            index = index + 1
        end
    end
end)

the line is line 46

Answer this question