Salutations, all. As the title suggests, I am having issues with picking up and throwing objects. I understand that the main problem may be because I’m handling it on the client, but I thought :SetNetworkOwner() let this happen, or perhaps I’m misinterpreting it. Regardless, they appear to sink on the server side yet are fine on the client.
My client code:
game:GetService("RunService").RenderStepped:Connect(function()
if GrabbedObject then
GrabbedObject:PivotTo(WorldMouse.CFrame * CFrame.new(5, 0, 0))
end
end)
game:GetService("UserInputService").InputBegan:Connect(function(Input, Processed)
if not Processed then
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
if Mouse.Target:IsDescendantOf(workspace:WaitForChild("Workspace"):WaitForChild("Pickupables")) and Mouse.Target.Parent:IsA("Model") and not Mouse.Target.Parent:GetAttribute("Grabbed") then
GrabbedObject = Mouse.Target.Parent
script:WaitForChild("RemoteEvent"):FireServer("MoveObject", GrabbedObject)
end
end
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(Input, Processed)
if Input.UserInputType == Enum.UserInputType.MouseButton1 and GrabbedObject then
script:WaitForChild("RemoteEvent"):FireServer("DropObject", GrabbedObject)
GrabbedObject = nil
end
end)
My server code:
script.Parent:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(Player, Type, Arg1)
if Type and Type == "MoveObject" then
GrabbedObject = Arg1
for i,v in pairs(GrabbedObject:GetDescendants()) do
if v:IsA("BasePart") then
v:SetNetworkOwner(Player)
end
end
GrabbedObject:SetAttribute("Grabbed", true)
elseif Type and Type == "DropObject" then
GrabbedObject = Arg1
GrabbedObject:SetAttribute("Grabbed", false)
for i,v in pairs(GrabbedObject:GetDescendants()) do
if v:IsA("BasePart") then
v:SetNetworkOwner(nil)
end
end
end
end)
Client view:
Server view:
If anyone can help, then cheers!