so i decided to make a dragging system using a dragdetector attached to a part and an alignposition constraint to make it follow the player when dragging said part.
i have implemented a network ownership changing system that uses the SetNetworkOwner()
function to change the physics calculation to the client of the player dragging the part, and switch it back to server physics calculation when the no player is dragging said part.
i came across an issue with the alignposition constraint where if i drag the part, the part would move to the player and thrust them away like this:
here’s what does the part look like in the explorer:
here’s replicated storage and serverscriptservice (run config is part of a run script):
and here’s all the code that’s within my scripts:
the eventsender script:
local repstorage = game.ReplicatedStorage
local event_netown = repstorage.NetOwnerShip
local dragdet = script.Parent
local grabbedpart = script.Parent.Parent
local alignpos = grabbedpart.AlignPosition
dragdet.DragStart:Connect(function(draggingplayer: Player)
event_netown:Fire(draggingplayer, grabbedpart)
task.wait()
local plrchar = draggingplayer.Character or draggingplayer.CharacterAdded:Wait()
local plrrootpart = plrchar:FindFirstChild("Humanoid").RootPart
local plrattachment = plrrootpart:FindFirstChild("GrabAttachment")
alignpos.Attachment1 = plrattachment
end)
dragdet.DragEnd:Connect(function(draggingplayer: Player)
event_netown:Fire(draggingplayer, grabbedpart)
task.wait()
alignpos.Attachment1 = nil
end)
the createrootattachment script:
local players = game.Players
players.PlayerAdded:Connect(function(newplayer: Player)
local plrcharacter = newplayer.Character or newplayer.CharacterAdded:Wait()
local plrchar_root = plrcharacter:WaitForChild("HumanoidRootPart")
local plrattachment = Instance.new("Attachment")
plrattachment.Parent = plrchar_root
plrattachment.Name = "GrabAttachment"
end)
and here’s the network ownership script:
local repstorage = game.ReplicatedStorage
local event_netown = repstorage.NetOwnerShip
event_netown.Event:Connect(function(grabbingplayer, grabbedpart)
if grabbedpart:GetNetworkOwner() ~= grabbingplayer then
grabbedpart:SetNetworkOwner(grabbingplayer)
print(grabbingplayer.Name .. " now calculates the physics of " .. grabbedpart.Name)
else
grabbedpart:SetNetworkOwner(nil)
print("the server now calculates the physics of " .. grabbedpart.Name)
end
end)
i hope what i provided was enough for you to help me fix the throwing issue.
p.s: i do know that the alignposition constraint defaults to the center of the attachment.