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)
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)