SHOW:
|
|
- or go back to the newest paste.
1 | local runService = game:GetService("RunService") | |
2 | ||
3 | ||
4 | local playersFolder = workspace:WaitForChild("Players") | |
5 | ||
6 | ||
7 | local petsPerRow = 5 | |
8 | ||
9 | ||
10 | local offsetX = 4 | |
11 | local offsetZ = 5 | |
12 | local offsetPlayer = 6 | |
13 | ||
14 | ||
15 | ||
16 | ||
17 | local function positionPets(character, playerFolder, deltaTime, sin, cos) | |
18 | local petCount = #playerFolder:GetChildren() | |
19 | local rows = math.ceil(petCount / petsPerRow) | |
20 | ||
21 | ||
22 | ||
23 | ||
24 | for i, pet in pairs(playerFolder:GetChildren()) do | |
25 | local row = math.floor( (i - 1) / petsPerRow) | |
26 | local col = (i - 1) % petsPerRow | |
27 | ||
28 | ||
29 | local characterSize = character:GetExtentsSize() | |
30 | local petSize = pet:GetExtentsSize() | |
31 | local petsInRow = math.min(petCount - row * petsPerRow, petsPerRow) | |
32 | ||
33 | ||
34 | local x = (col - petsInRow/2 + 0.5) * offsetX | |
35 | local y = petSize.Y/2 - characterSize.Y/2 | |
36 | local z = (row * offsetZ) + offsetPlayer | |
37 | ||
38 | ||
39 | if pet:FindFirstChild("Attack").Value ~= nil then | |
40 | - | local position = (pet:FindFirstChild("Attack").Value.CFrame * CFrame.new(x, 0, z)).p |
40 | + | |
41 | - | local lookAt = pet:FindFirstChild("Attack").Value.Position |
41 | + | local position = (pet:FindFirstChild("Attack").Value.CFrame * CFrame.new(x, 0, z)).p |
42 | local lookAt = pet:FindFirstChild("Attack").Value.Position | |
43 | pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(CFrame.new(position, lookAt) * CFrame.new(0, 1 + sin, 0) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1)) | |
44 | else | |
45 | local position = (pet:FindFirstChild("Attack").Value.PrimaryPart.CFrame * CFrame.new(x, 0, z)).p | |
46 | local lookAt = pet:FindFirstChild("Attack").Value.PrimaryPart.Position | |
47 | pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(CFrame.new(position, lookAt) * CFrame.new(0, 3 + math.sin(time()*7)/2, 0) * CFrame.fromEulerAnglesXYZ(cos,0,0) ,0.1)) | |
48 | end | |
49 | else | |
50 | if character.Humanoid.MoveDirection.Magnitude > 0 then | |
51 | if pet:FindFirstChild("Walks") then | |
52 | pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( | |
53 | character.PrimaryPart.CFrame * CFrame.new(x, y + sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1)) | |
54 | elseif pet:FindFirstChild("Flying") then | |
55 | pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( | |
56 | character.PrimaryPart.CFrame * CFrame.new(x, y / 2 +math.sin(time()*3)+1, z), 0.1)) | |
57 | end | |
58 | else | |
59 | if pet:FindFirstChild("Walks") then | |
60 | pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( | |
61 | character.PrimaryPart.CFrame * CFrame.new(x, y, z) ,0.1)) | |
62 | elseif pet:FindFirstChild("Flying") then | |
63 | pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp( | |
64 | character.PrimaryPart.CFrame * CFrame.new(x, y / 2 + math.sin(time()*3)+1, z) , 0.1)) | |
65 | end | |
66 | end | |
67 | end | |
68 | end | |
69 | end | |
70 | ||
71 | ||
72 | ||
73 | ||
74 | runService.RenderStepped:Connect(function(deltaTime) | |
75 | local sin = (math.sin(15 * time() + 1.6)/.5)+1 | |
76 | local cos = math.cos(7 * time() + 1) / 4 | |
77 | ||
78 | ||
79 | ||
80 | ||
81 | for i, playerFolder in pairs(playersFolder:GetChildren()) do | |
82 | local player = game.Players:FindFirstChild(playerFolder.Name) | |
83 | if player ~= nil then | |
84 | local character = player.Character or nil | |
85 | if character ~= nil then | |
86 | positionPets(character, playerFolder, deltaTime, sin, cos) | |
87 | end | |
88 | end | |
89 | end | |
90 | end) | |
91 |