My grabbing system movement physics doesn't replicate on server-side

There is absolutely no problem in first person view.
But however when people sees you grabbing something, they can’t see the object being grabbed.
And after you released your left mouse button, other people will see it teleport to its final position.

I tried the network ownership but it doesn’t work.

I wonder why my previous poorly code grabbing system would work even without setting the NetworkOwnership

3 Likes

I’m just gonna take a guess and say that the animating for it is done client-side in a LocalScript. The reason it won’t show for other players is because whatever is done on the client will only show for that client - since it doesn’t tell the server what is done. You can use a RemoteEvent to communicate between the client and the server, and I would suggest doing the animating server-side - this way it will show for all the players.

That grabbing system is not animated. I use alignPosition and AlignAngle

But do I really have to use remote event to send the coordinates? Wouldn’t it cause performance issue?

1 Like

By ‘animated’, I was just referencing the drag effects. Are you using a DragDetector under the block or are you using the player’s mouse? A DragDetector could be used server-side without excessive firing of the RemoteEvent.

1 Like

I’m not using the DragDetector, because it behaves weird and can potentially cause players to abuse the mechnic to perform upexpected actions.

Plus, before the player grabs the object the server will need to check if the object is owned by the player.

By the way, for some reason my previous old grabbing system was all client side but still able to grab object somehow.

1 Like

The player’s mouse only exists for that player, so it can’t be passed along a RemoteEvent. You might just have to fire the RemoteEvent a lot, passing the mouse’s CFrame along the event each time. That way, even if it misses a few of the firings, it wouldn’t really matter too much because it would update so quickly.

I’m not too sure how impacting this would be on performance, you might just have to test and see.

Client-side:

local rStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local player = players.LocalPlayer
local event = rStorage:WaitForChild("RemoteEvent") --RemoteEvent path here

local mouse = player:GetMouse()

--then, when needed:
event:FireServer(mouse.Hit)

Server-side:

local rStorage = game:GetService("ReplicatedStorage")
local event = rStorage.RemoteEvent --RemoteEvent path here
event.OnServerEvent:Connect(function(player, mouseCFrame)
    --moving code here
end)

Then, do what you will with that server-side.

local player = game.Players.LocalPlayer 
local mouse = player:GetMouse() 
local camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local Part
local P
local target 
local down
mouse.Button1Down:connect(function() 
	if mouse.Target ~= nil then
		local Grabbing = mouse.Target.Parent:FindFirstChild("Grabbing") or mouse.Target:FindFirstChild("Grabbing")
		if mouse.Target.Locked == false and Grabbing then
			target = mouse.Target 
			down = true 
			Part = Instance.new("Part")
			Part.Parent = game.Workspace
			Part.Transparency = 0.5
			Part.Size = Vector3.new(1,1,1)
			Part.CFrame = CFrame.new(camera.CFrame.Position,target.Position)
			Part.Position = mouse.hit.p
			Part.CanCollide = false
			mouse.TargetFilter = Part
			mouse.TargetFilter = target 
			local Weld = Instance.new("WeldConstraint")
			Weld.Parent = Part
			Weld.Part0 = Part
			Weld.Part1 = target
			local gyro = Instance.new("BodyGyro") 
			gyro.Name = "Gyro"
			gyro.Parent = Part
			gyro.MaxTorque = Vector3.new(500, 500, 500)
			local force = Instance.new("BodyPosition") 
			force.Name = "Force" 
			force.Parent = Part
			force.P = 25000
			force.MaxForce = Vector3.new(10000, 10000, 10000) 
		end
	end
end)

game:GetService("RunService").RenderStepped:Connect(function() 
	if down == true and target ~= nil and Part then 
		Part.Gyro.CFrame = CFrame.new(camera.CFrame.Position,Part.Position)
		Part.Force.Position = camera.CFrame.Position + (mouse.UnitRay.Direction * 5)
	end 
end) 

mouse.Button1Up:connect(function() 
	if Part then 
		if Part:FindFirstChild("Gyro") or Part:FindFirstChild("Force") then 
			Part:Destroy()
		end
	end
	down = false
	mouse.TargetFilter = nil
	target = nil 
end)

This was my old grabbing code, but I’m confused on why my old code is able to replicate the movement even though it was 100% client side.(Still works today)

I don’t think that firing remote event like with a few frame gap is a good idea. Because my game is kinda performance heavy already.

1 Like

sorry I’m out of ideas for now, I’ll let you know if I think of anything

No just out the moving code in a server script so when they grab you send the Arm and Hand or whatever so the server knows they you make they grab.

Wait, it turns out switching into deprecated bodymovers would make the movement replicate. The newer version perhaps doesn’t allow cross-side replicattion?

yeah it works now but I’m still a little bit worried about that being “Deprecated”

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