Hello, I’ve been making a pet system and I am trying to give my pets and idle animation.
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local WalkAnimationData = {
TweenInfo = TweenInfo.new(.1, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, true, 0),
}
local IdleAnimationData = {
TweenInfo = TweenInfo.new(.5, Enum.EasingStyle.Back, Enum.EasingDirection.InOut, 0, true, 0),
}
local Circle = 2 * math.pi
local radius = 7
local function getXAndZPositions(angle)
local x = math.cos(angle) * radius
local z = math.sin(angle) * radius
return x, z
end
local lookAtCFrame
local HoverDB = false
local db = false
local function IncrementPet()
local PetsFolder = workspace.PetsFolder:FindFirstChild(game.Players.LocalPlayer.UserId):GetChildren()
local player = game.Players.LocalPlayer
local char = player.Character
local hrp = char:FindFirstChild("HumanoidRootPart")
local hum = char:FindFirstChild("Humanoid")
for i, part in pairs(PetsFolder) do
local angle = i * (Circle / #PetsFolder)
local x, z = getXAndZPositions(angle)
local position = (hrp.CFrame * CFrame.new(x, 0, z)).p
lookAtCFrame = CFrame.lookAt(position, hrp.Position)
lookAtCFrame = CFrame.new(lookAtCFrame.p) *
CFrame.Angles(0, math.atan2(
-lookAtCFrame.LookVector.X,
-lookAtCFrame.LookVector.Z), 0)
local MoveDirection = hum.MoveDirection
local PlayerMoving = MoveDirection.Magnitude > .5
part.GuidePart.CFrame = lookAtCFrame
if PlayerMoving then
lookAtCFrame = CFrame.new(lookAtCFrame.Position) * CFrame.Angles(
0, math.atan2(-MoveDirection.X, -MoveDirection.Z), 0
)
if part.GuidePart.CanFly.Value == false then
local function Walk(part)
local T1 = TweenService:Create(part.GuidePart, WalkAnimationData.TweenInfo,{CFrame = lookAtCFrame + Vector3.new(0,12,0)})
T1:Play()
T1.Completed:Wait()
local T2 = TweenService:Create(part.GuidePart, WalkAnimationData.TweenInfo,{CFrame = lookAtCFrame - Vector3.new(0,12,0)})
T2:Play()
T2.Completed:Wait()
end
Walk(part)
part.GuidePart.CFrame = lookAtCFrame
end
part.GuidePart.CFrame = lookAtCFrame
--HoverTween(part)
end
end
end
wait(.3)
while RunService.Stepped:Wait() do
local PetFolder = game.Workspace.PetsFolder:FindFirstChild(game.Players.LocalPlayer.UserId):GetChildren()
if #PetFolder ~= 0 then
IncrementPet()
end
end
Here is the script for client pets so far. It works fine but I want to make it better. The problem is that the pets will preform the animation 1 at a time and I don’t know how to fix this. I just want the pets to be able to all walk at the same time. I tried coroutines but I cant find a good way of implementing them.
I know its because the the loops but I don’t know any better ways to do this.
Thanks.