Pet Follow BUG (SCRIPTING HELP)

You can write your topic however you want, but you need to answer these questions:

  1. So im working on a pet follow system and I want it to be server sided so everyone can see eachothers pets since I dont want it to just be client sided.

  2. The issue is the pets movement is jittery and weird as it shows in the (Video Below)
    robloxapp-20230730-1941067.wmv (60.0 KB)

3.Here is my script

local Players = game:GetService("Players")

local function getXAndZPositions(angle, radius)
	local x = math.cos(angle) * radius
	local z = math.sin(angle) * radius
	return x, z
end

local function setupCircularMovement(character)
	local hrp = character:WaitForChild("HumanoidRootPart")

	local parts = {}
	local numberOfParts = 8

	for _ = 1, numberOfParts do
		local part = Instance.new("Part")
		part.Anchored = true
		part.CanCollide = false
		part.Parent = workspace
		table.insert(parts, part)
	end

	local fullCircle = 2 * math.pi
	local radius = 10

	local initialHeights = {}
	for i, _ in ipairs(parts) do
		initialHeights[i] = parts[i].Position.Y
	end

	local lastTime = tick()
	local step = 0.02
	local offset = 0

	game:GetService("RunService").Heartbeat:Connect(function()
		local currentTime = tick()
		local deltaTime = currentTime - lastTime
		lastTime = currentTime

		offset = offset + step * deltaTime

		local currentPosition = hrp.Position

		for i, part in pairs(parts) do
			local angle = i * (fullCircle / #parts) + offset
			local x, z = getXAndZPositions(angle, radius)

			local targetPosition = currentPosition + Vector3.new(x, 0, z)
			local targetHeight = initialHeights[i] + 0.2 * math.sin(currentTime * 2)  -- Slower bounce effect
			targetPosition = targetPosition + Vector3.new(0, targetHeight, 0)

			part.CFrame = CFrame.new(targetPosition)
		end
	end)
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		setupCircularMovement(character)
	end)
end)

for _, player in ipairs(Players:GetPlayers()) do
	if player.Character then
		setupCircularMovement(player.Character)
	end
end

There is the script. Thanks to anyone who helps!

1 Like

any help is great as this is a bug I been dealing with for a while

Do not do this, you will be putting a lot of unnessacary networking data from the Server which can slow down your game, instead what you should to is just tell the Server what pet the Player actually has, and then displaying and Animating that said pet with the code to move it on the Client, it will be a lot smoother Client Side, and it will be much more efficient than Server side.

Small Thing:

sin is y, not z.

How would I do this as I’m a little confused as to what to do

You can make it like:
It will detect someone joins the server
Fire all the Cilent include the player’s asset and what are they using and stuff to make the pet appear.
Because event can send values and instance to different events using “FireAllCilent(value)” Or “FireServer(Value)”.It will visible to everyone if you use FireAllCilent and it won’t cause lags also because it only visible on all the player’s cilent

Video shows a blank white menu …

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