Problem with ball movement script

Hello! I am making a ball movement script but for some reason, it only works if it runs on the server. If I try it on the client, the values change but the ball only moves after a few minutes. Does anyone have any idea as to why this is happening? This is my code:

game:GetService("RunService").Stepped:Connect(function()
	for i, v in pairs(game.Workspace.Balls:GetChildren()) do
		local plr = game.Players:GetPlayerByUserId(v.Name)
		
		if plr and v then
			if plr.Character and v then
				local char = plr.Character

				if v then
					if v.PrimaryPart:FindFirstChild("VectorForce") then
						v.PrimaryPart.VectorForce.Force = plr.Character.Humanoid.MoveDirection * 3000
					end
				end
			end
		end
	end
end)

(Each ball is a model and it’s name is the ID of the player)

You may want to set the ball’s NetworkOwnership to the player that will be moving it. Otherwise the sever owns it and will determine how it moves (for the most part)

ball:SetNetworkOwner(player)
ball.Name = player.UserID

As a local script it should only move the local player’s ball

local LocalPlayer = game:GetService("Players").LocalPlayer
game:GetService("RunService").Stepped:Connect(function()
    local ball = game.Workspace.Balls:FindFirstChild(LocalPlayer.Name)
    if ball then
        ball.PrimaryPart.VectorForce.Force = LocalPlayer.Character.Humanoid.MoveDirection * 3000
    end
end)

Thank you so much, it worked! For some reason, I did not think of this

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