I am creating a pet following system, but the pets in this system do not move smoothly, can you help me? Also PetSlot is Model.
local TweenService = game:GetService("TweenService")
local AnimDebounce = false
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
workspace:WaitForChild(player.Name)
local HRP = character:WaitForChild("HumanoidRootPart")
local PetSlot = game.ReplicatedStorage.PetSlot:Clone()
PetSlot.Parent = character
PetSlot.PrimaryPart = PetSlot:FindFirstChild("PetPrimaryPart")
local HRPPosition = HRP.Position
game:GetService("RunService").Heartbeat:Connect(function()
if AnimDebounce == false then
AnimDebounce = true
HRPPosition = HRP.Position
local function createFollowAnimation(partToFollow, targetPart)
local tweenInfo = TweenInfo.new(
0.25, -- Süre
Enum.EasingStyle.Quad, -- Easing stili (opsiyonel)
Enum.EasingDirection.Out -- Easing yönlendirmesi (opsiyonel)
)
local goal = {}
goal.CFrame = targetPart.CFrame
local tween = TweenService:Create(partToFollow, tweenInfo, goal)
tween:Play()
tween.Completed:Connect(function()
if partToFollow.CFrame ~= HRP.CFrame then
createFollowAnimation(PetSlot.PrimaryPart, HRP)
else
AnimDebounce = false
end
end)
end
createFollowAnimation(PetSlot.PrimaryPart, HRP)
end
end)
end)
end)