ServerSided throw script lagging part?

When this was local it didn’t have that 1 second delay when you throw the part, but i changed the localscript into a server script, and now It just lags like .50s every throw

for short, this didn’t have a delay when it was a localscript:

ServerScript:

function HandleRockThrow(plr, direction)
	local Monster = game:GetService("Workspace"):FindFirstChild("Monster")
	local location = Vector3.new(0, 0, 0)
	local Clone = game.ReplicatedStorage.Pebble:Clone()
	Clone.Parent = workspace
	Clone:SetNetworkOwnershipAuto()
	Clone:PivotTo(plr.Character.HumanoidRootPart.CFrame * CFrame.new(0, 1, 0))
	
	local forceMultipliter = 100 * Clone:GetMass()
	Clone:ApplyImpulse(direction * forceMultipliter)
	Clone.Touched:Connect(function(touched)
		if touched.Parent ~= plr.Character and Clone:FindFirstChild("pebble") and Clone.touched.Value == false then
			Clone.touched.Value = true
			print(touched.Name)
			Clone.pebble:Play()
			local hitVisible = Instance.new("Part")
			hitVisible.Size = Vector3.new(0.1, 0.1, 0.1)
			hitVisible.Anchored = true
			hitVisible.CanCollide = false
			hitVisible.BrickColor = BrickColor.new("Lime green")
			hitVisible.Parent = workspace
			hitVisible.Position = Clone.Position
			hitVisible.Material = Enum.Material.Neon
			location = Clone.Position
		end
	end)

Localscript:

local direction = game.Players.LocalPlayer:GetMouse().Hit.LookVector

local RockEvent = Events.HandleRockThrow:InvokeServer(direction)
1 Like

With parts, you can imagine a ‘bubble’ around the character. Parts inside the bubble have their physics controlled by the player, once that part leaves the bubble the physics gets controlled by the server. This changing of ownership of the physics is what causes the slight pause when leaving the bubble as seen in your video. The reason the local script was fine was because it created a local part, which is always has its physics controlled by the player who created it.

To fix this add this after throwing the rock:

Rock:SetNetworkOwner(nil)

Or

Rock:SetNetworkOwner(player)

This makes it so there isn’t a change in physics ownership and no delay

1 Like