Ball's Position not being set to Torso Position

Hello, I made a script that’s supposed to position a ball on the players torso, and grows in and out. However, whenever the player moves the position of the ball changes to a couple inches back.
heres what it looks like
https://gyazo.com/ab26cd3737e3763cb2db2f18af368f34
as you can see the ball does not start off on the players torso

local Players = game:GetService("Players")
local db = {}

Players.PlayerAdded:Connect(function(plr)
    db[plr] = true
end)
Players.PlayerRemoving:Connect(function(plr)
    db[plr] = nil
end)

script.Electric.OnServerEvent:Connect(function(plr)
	 if db[plr] == true then
	db[plr] = false
	char = plr.Character
	ws = char.Humanoid.WalkSpeed
	_G.FAISDJFAI = plr.Name
	print(_G.FAISDJFAI)
	ball = game.ReplicatedStorage.TOOLS.DischargeBall:Clone()
	char.Torso.Anchored = true
	animation = char.Humanoid:LoadAnimation(script.Animation)
	animation:Play()
	wait(1)
	ball.Position = char.Torso.Position
	ball.Parent = game.Workspace
	ball.Anchored = true
	r = 0
	repeat
		wait(.001)
		r = r + 1
		ball.Size = ball.Size + Vector3.new(1,1,1)
	until r == 40
	dmg = script.dmg:Clone()
	dmg.Parent = ball
	dmg.Disabled = false
	wait(5)
	repeat
		wait(.001)
		r = r + 1
		ball.Size = ball.Size - Vector3.new(1,1,1)
	until r == 80
	r = 0
	ball:Destroy()
	char.Torso.Anchored = false
	wait(20)
	 db[plr] = true
	end
end)

I on purpose anchored the player for when the player moves then added a wait, then it changes the ball to the players torso which I thought should’ve worked but didnt.

1 Like

Try setting the Ball’s CFrame instead of its Position.
ball.CFrame = char.Torso.CFrame

Just tried that, it doesn’t fix it.

How about anchoring the ball before setting the parent?

Just tried that, it doesn’t fix it.

I only took a quick look but it seems like a classic case of ping.

It takes time for information to replicate/be sent from client > server or vice versa. On Roblox character movement is controlled by the client itself, so changes to the player object made on the server have to be replicated back to the client.

This means when the server makes the ball, and tells the client it can’t move any more, the client can still move till it gets that message (but the ball is already been created). An easy fix would be to set the CFrame of the ball to the Torso position each step of the animation:

repeat
    wait(.001)
    r = r + 1
    ball.Size = ball.Size + Vector3.new(1,1,1)
    ball.CFrame = char.Torso.CFrame
until r == 40

This may still create a slight delay in which the player is moving and the ball follows them. To minimize this, handle anchoring the torso on the client side, and wait for a callback from the server through a RemoteFunction instead of RemoteEvent to unanchor it.

4 Likes