Problems with humanoid and its root part

  1. What do you want to achieve? Keep it simple and clear!
    I want to find out why the humanoid is separated from its rootpart, specifically on local server and the team test

  2. What is the issue?
    For some reason, the goalkeepers work fine on a normal roblox studio test, but when it comes to team testing and local server, they start behaving weirdly. For some reason, their root parts are away from the character, and I have no idea why.

  3. What solutions have you tried so far?
    I tried consulting other developers, and looking for solutions on different sources, but, unfortunately, no luck.

robloxapp-20230328-1155173.wmv (3.2 MB)

Here is the code:

local Char = script.Parent

local Humanoid = Char:WaitForChild("Humanoid")
local HumPart = Humanoid.RootPart



while true do
	wait()
	
	local Ball = workspace:WaitForChild("Ball") 
	
	if Ball.Position.Z <= script.Parent.Stop2.Position.Z and Ball.Position.Z >= script.Parent.Stop1.Position.Z and HumPart.Position.Z ~= Ball.Position.Z then
		HumPart.Position = Vector3.new(Char:WaitForChild("Pos").Position.X,HumPart.Position.Y,Ball.Position.Z)
		if Ball.Position.Y >= HumPart.Position.Y + 5  and (workspace.Ball.Position - workspace.GoalKeepers.GoalKeeper.Pos.Position).Magnitude <= 15 then
			Humanoid.Jump = true
		end
	elseif (HumPart.Position.Z == Ball.Position.Z) or (Ball.Position.Z > script.Parent.Stop2.Position.Z or Ball.Position.Z < script.Parent.Stop1.Position.Z) then
	end
end

As I already mentioned, the goalkeepers work fine in a normal roblox studio test, which makes me confused about why would it not work the same in team test.