-
I want to create a working pet follow system that creates a circle around the player that also shows on the server so everyone can see the players pets.
-
Im having issues with the client not showing the players pets when I clone them but when I use instance.new to create a part it shows on the server but when I clone the pet it doesnt work. Here is an example with it working with a part.
-
I have tried to solve this issue multiple times but it does not work so if anyone can help me that would be appreciated as I have been trying to fix it for weeks now.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function setupCircularRotationAndBounce(character)
local hrp = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local parts = {}
local numberOfParts = 8
for _ = 1, numberOfParts do
local part = ReplicatedStorage.Dog
part.Anchored = false
part.CanCollide = false
part.Parent = script.Parent
table.insert(parts, part)
end
local fullCircle = 2 * math.pi
local radius = 16
local bounceAmplitude = 0.2
local function updateRadius()
local currentTime = tick()
local isWalking = humanoid.WalkSpeed > 0
local isJumping = humanoid:GetState() == Enum.HumanoidStateType.Jumping
local dogCount = 0
for _, part in pairs(character:GetChildren()) do
if part.Name == "Dog" then
dogCount = dogCount + 1
end
end
radius = 10 + (dogCount * 0.5) -- Adjust the multiplier for extending the circle
for i, part in pairs(parts) do
local angle = (i * (fullCircle / #parts)) + ((currentTime * 0.5) % fullCircle)
local x, z = math.cos(angle) * radius, math.sin(angle) * radius
local targetPosition = hrp.Position + Vector3.new(x, 0, z)
-- Add vertical bouncing if the player is walking or jumping
if isWalking or isJumping then
local bounceHeight = math.abs(math.sin(currentTime * 5)) * bounceAmplitude
targetPosition = targetPosition + Vector3.new(0, bounceHeight, 0)
end
part.Position = targetPosition
end
end
game:GetService("RunService").Heartbeat:Connect(function()
updateRadius()
end)
character.ChildAdded:Connect(function(child)
if child.Name == "Dog" then
updateRadius()
table.insert(parts, child)
end
end)
character.ChildRemoved:Connect(function(child)
if child.Name == "Dog" then
updateRadius()
local indexToRemove
for i, part in ipairs(parts) do
if part == child then
indexToRemove = i
break
end
end
if indexToRemove then
table.remove(parts, indexToRemove)
end
end
end)
updateRadius() -- Initial update
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
setupCircularRotationAndBounce(character)
end)
end)
for _, player in ipairs(Players:GetPlayers()) do
if player.Character then
setupCircularRotationAndBounce(player.Character)
end
end
Here is the script above and also I made it a local script because its smoother and on the server it is laggy.