Untitled
unknown
lua
8 months ago
2.1 kB
6
Indexable
Never
local runService = game:GetService("RunService") local playersFolder = workspace:WaitForChild("Players") local petsPerRow = 5 local offsetX = 4 local offsetZ = 5 local offsetPlayer = 6 local function positionPets(character, playerFolder, deltaTime, sin, cos) local petCount = #playerFolder:GetChildren() local rows = math.ceil(petCount/petsPerRow) for i, pet in pairs(playerFolder:GetChildren()) do local row = math.floor((i-1)/petsPerRow) local col = (i-1)%petsPerRow local characterSize = character:GetExtentsSize() local petSize = pet:GetExtentsSize() local petsInRow = math.min(petCount-row*petsPerRow, petsPerRow) local x = (col-petsInRow/2+0.5)*offsetX local y = petSize.Y/2-characterSize.Y/2 local z = (row*offsetZ) + offsetPlayer if character.Humanoid.MoveDirection.Magnitude > 0 then if pet:FindFirstChild("Walks") then pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( character.PrimaryPart.CFrame * CFrame.new(x, y + sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1)) elseif pet:FindFirstChild("Flying") then pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( character.PrimaryPart.CFrame * CFrame.new(x, y / 2 +math.sin(time()*3)+1, z), 0.1)) end else if pet:FindFirstChild("Walks") then pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( character.PrimaryPart.CFrame * CFrame.new(x, y, z) ,0.1)) elseif pet:FindFirstChild("Flying") then pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( character.PrimaryPart.CFrame * CFrame.new(x, y / 2 + math.sin(time()*3)+1, z) , 0.1)) end end end end runService.RenderStepped:Connect(function(deltaTime) local sin = (math.sin(15 * time() + 1.6)/.5)+1 local cos = math.cos(7 * time() + 1) / 4 for i,playerFolder in pairs(playersFolder:GetChildren()) do local player = game.Players:FindFirstChild(playerFolder.Name) if player ~= nil then local character = player.Character or nil if character ~= nil then positionPets(character, playerFolder, deltaTime, sin, cos) end end end end)
Leave a Comment