-
What do you want to achieve?
I’m trying to make an inventory system that lets you pick up and drop items.
When you drop, the items are affected by physics and brought to the ground.
When items are picked up, their network ownership gets passed to the player. -
What is the issue?
There’s a noticeable delay to other clients when the item is dropped.
https://gyazo.com/d109456092683455de3c8f9c1795495f -
What solutions have you tried so far?
I tried removing the lines that pass the network ownership to the player, but that just ends up creating a delay for both clients.
I did look around the forum, but none of the posts related to network ownership seem to be helping, or are just unrelated to my situation and I don’t understand them.
Basically, in the Gif above you can see on the left screen that the item dropped by the other player has a delay before physics affect it.
The ModuleScript I made on the server to give and take items from players and Humanoids alike.
function ServerInventoryModule:GiveItem(InventoryFolder,SlotValue,ItemValue,Clone,Player)
if SlotValue.Value then
return SlotValue.Name.." already has an item value."
end
if Clone then
ItemValue = ItemValue:Clone()
end
ItemValue:SetAttribute("Pickable",false)
local ItemModel = ItemValue.Value
if ItemModel then
ItemModel.Parent = workspace
for _,BasePart in pairs(ItemModel:GetDescendants()) do
if BasePart:IsA("BasePart") then
BasePart:SetNetworkOwner(Player)
end
end
ItemModel.Parent = ReplicatedStorage
end
ItemValue.Parent = InventoryFolder.Items
SlotValue.Value = ItemValue
end
function ServerInventoryModule:DropItem(SlotValue,Origin,IsDead,Player)
local ItemValue = SlotValue.Value
if not ItemValue then
return SlotValue.Name.." has no item value."
end
local ItemModel = ItemValue.Value
if ItemModel then
ItemValue.Parent = workspace
ItemModel.Parent = ItemValue
ItemModel:PivotTo(Origin)
local PrimaryPart = ItemModel.PrimaryPart
if PrimaryPart then
local AngleRandom = Random.new():NextNumber(-10,10)
PrimaryPart.AssemblyAngularVelocity = Vector3.new(AngleRandom,AngleRandom,AngleRandom)
if IsDead then
local LinearRandom = Random.new():NextNumber(-20,20)
PrimaryPart.AssemblyLinearVelocity = Vector3.new(LinearRandom,0,LinearRandom)
end
end
task.spawn(function()
task.wait(1)
ItemValue:SetAttribute("Pickable",true)
for _,BasePart in pairs(ItemModel:GetDescendants()) do
if BasePart:IsA("BasePart") then
BasePart:SetNetworkOwner()
end
end
end)
else
ItemValue:Destroy()
end
SlotValue.Value = nil
end
In simple steps:
- Player picks up item
- Parent item ObjectValue to their inventory folder
- Set item model’s network owner to player
- Parent item model to ReplicatedStorage
- Player drops item
- Parent item ObjectValue to workspace
- Parent item model to item ObjectValue
- Set item model network owner to server after 1 second
Is the problem inevitable?
Am I using SetNetworkOwner()
wrong?
Thanks for reading