Roblox physics lagging?

When i tried to add the force its simply just lagged, I want it to be like popping from the bottle.
This is what i’ve tried :

local CS = game:GetService("CollectionService")

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local AnimLoader = require(game:WaitForChild("ReplicatedStorage"):WaitForChild("Module"):WaitForChild("AnimationLoader"))

local animationid = script:WaitForChild("Animation").AnimationId

local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")

local track = AnimLoader.GetAnimation(animationid, animator)

local function PoppingCap(tool)
	local cap = tool:FindFirstChild("Cap")
	
	for _, child in ipairs(cap:GetChildren()) do
		if child:IsA("WeldConstraint") then
			child:Destroy()
		end
	end
	
	if cap then
		cap.Position = cap.Position + Vector3.new(0, 0.2, 0)
		local force = Instance.new("BodyVelocity")
		force.Velocity = Vector3.new(math.random(-5,5), 20,math.random(-5,5))
		force.MaxForce = Vector3.new(1e5,1e5,1e5)
		force.P = 1e4
		force.Parent = cap
		
		game:GetService("Debris"):AddItem(force,0.3)
		
		cap.Anchored = false
	end
end

char.ChildAdded:Connect(function(tool)
	if tool:IsA("Tool") and CS:HasTag(tool,"Potion") then
		tool.Activated:Connect(function()
			track:Play()
			wait(0.2)
			PoppingCap(tool)
		end)
	end
end)

Here is The Video

BodyVelocity is outdated and would use old physics engine
Obviously it would be very bad
Use VectorForce/LinearForce instead

1 Like

@VentorRB Can you clarify how it “lagged”?
Is it choppy, not working, stuttery? Show a video if possible.
Missed the link, apologies!

What do you mean by “use old physics engine”?
Roblox removed the old spring physics solver a long time ago, and it’d also be impossible to switch between it at runtime.

1 Like

Is the cap welded by chance


This causes a desynchronization, the “lag” is likely caused by the client not simulating the cap because it was part of one rigid assembly (and still is on the server).

You’ll need to unweld it on the server.

Ah… i see, i forgot abt the server and client sided thing, ty

I agree. Never use body velocity for new scripts as it causes all kinds of unintended bugs/behavior issues. ex: body velocity often applies force differently on mobile vs PC.