Pet Follow (BUG)

  1. 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.

  2. 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.

  3. 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.

2 Likes

Any Help is appreciated as I have been struggiling on this for weeks.

2 Likes

I don’t quite understand this part. Are you suppose to clone the dog and reposition it or something?

2 Likes
  1. Replication: If the ReplicatedStorage.Dog object is a model or contains other parts, make sure that all parts of the model are being cloned and replicated to the client properly. If any parts are missing or not replicated, it could lead to the behavior you’re experiencing. Verify that the Dog object contains all the necessary parts and that these parts are properly parented and replicated.
  2. Parenting: In your code, you’re parenting the cloned part objects to script.Parent, which might not be a suitable parent for these objects. Make sure you’re parenting the cloned parts to the appropriate parent object that is visible to the client. For instance, if the pets should be visible to everyone, consider parenting them to the player’s character or workspace.
  3. Workspace vs. Player: Generally, it’s better to place objects that are intended to be visible to all players in the Workspace rather than ReplicatedStorage. If you want the pets to be visible to all players on the server, consider parenting them to the Workspace.
  4. Model Cloning: If your ReplicatedStorage.Dog object is a model, you might need to use Instance.new to create new instances of it, instead of cloning it directly. For example:
local newDog = Instance.new("Model")
for _, part in pairs(ReplicatedStorage.Dog:GetChildren()) do
    local clonedPart = part:Clone()
    clonedPart.Parent = newDog
end
newDog.Parent = workspace  -- Parent to the appropriate location
  1. Check Output: Monitor the Output and Error panes in the Studio while testing to see if there are any error messages or warnings related to object replication or parenting.
  2. Networking: Make sure you’re testing this on an actual server environment rather than just locally in Studio. Some issues might not be apparent in the local testing environment.
2 Likes

It is to create multiple dogs based on the number of parts variable

2 Likes

I want it to be located in the players character.

2 Likes

Thanks dude this worked I just had to create a new model

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.