Physics Not Applying Immediately

Currently, I’m trying to make an item throwing system. How it currently works is that you have a tool, and you hold down a button to charge up. Once you let go, it deletes the tool, finds the corresponding model in ReplicatedStorage, and clones that model. After that, I am applying a LinearVelocity to the part, but the part freezes in midair for a second before it applies. Is there any fix to this physic delay?

Relevant Code (ignore For Loop, that’s for another part of the system)

event.OnServerEvent:Connect(function(player, tool, strength)
local object = objects:FindFirstChild(tool.Name):Clone()
object:AddTag(“Pickup”)
local continue = true
for i,v in player:FindFirstChild(“HeldObjects”):GetChildren() do
if v.Value == objects:FindFirstChild(tool.Name) and continue == true then
continue = false
v.Value = nil
end
end
object.Parent = workspace
object.Position = player.Character.PrimaryPart.Position + player.Character.PrimaryPart.CFrame.LookVector * 3
tool:Destroy()
local attachment = Instance.new(“Attachment”)
attachment.Parent = object
local velocity = Instance.new(“LinearVelocity”)
velocity.Parent = attachment
velocity.Attachment0 = attachment
game.Debris:AddItem(attachment, 0.1 * strength)
velocity.VectorVelocity = player.Character.PrimaryPart.CFrame.LookVector * (strength + 3) * 10

end)

Try and clone the part beforehand. Parent a linearvelocity to it already in ReplicatedStorage. Also, maybe think of giving the node ownership to the player or, in alternative, simulate the throw on the client but do the calculations and replications on the server. These solutions give the appearence of no lag to the player.

1 Like

Giving node ownership to the player was what worked, thanks for the help!

1 Like

Before you continue, note: giving node ownership implies 2 VERY important elements:

  1. client simulates the physics of the object, the server will NOT check. You’ll have to create your own anti-exploit by doing eventually some raycast or smth else and see if it’s possible for the client to have thrown the object from that pos.
  2. other clients will see smth different. Although for the client it’s instantaneous, he acts as a server, so other clients feel the lag. This implies that if the client sees a player getting hit, this is not necessarily the case for the other players. It’s necessary to do some prediction, meaning that we want to find a way in-between the necessities of speed and accuracy for all players.
1 Like

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