Player occasionally get's flung into the farlands after using BodyVelocity on them

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the player to be able to dash in the direction of it’s humanoid’s MoveDirection.

  2. What is the issue? Include screenshots / videos if possible!
    From what I’ve seen, the player is flung to the farlands (a point where the player is so far away their avatar starts glitching) and dies, when they manage to perfectly time jumping and dashing at the same time. this issue is more likely to occur when there are a lot of enemy npc’s and the game starts lagging.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried countering this issue by shortening the window the player has to time it perfectly by deleting the BodyVelocity faster and increasing it’s power to accommodate for how fast it gets deleted, but this only makes the problem less likely to happen, not entirely erase it.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is my dash script:

local rem = game.ReplicatedStorage.Dash
local staminaPenalty = 50

rem.OnServerEvent:Connect(function(plr, Hum)
	local stam = Hum:FindFirstChild("Stamina")
	local Force = 360000000
	local Speed = 36000000
	if Hum.FloorMaterial == Enum.Material.Air then
		Force = Force/2 -- this makes the player slower if they are on air, since the power of the dash will be amplified when they are in air
		Speed = Speed/2
	end

	Hum.WalkSpeed += 30
	stam.Value -= staminaPenalty

	local TotalForce = Force

	local KnockBack = Instance.new("BodyVelocity")
	KnockBack.Parent = plr.Character:FindFirstChild("HumanoidRootPart")

	KnockBack.MaxForce = Vector3.new(TotalForce,0,TotalForce)
	KnockBack.Velocity = Hum.MoveDirection * Speed
	

	task.wait(0.0001)

	KnockBack:Destroy()
	task.wait(.3)
	Hum.WalkSpeed = Hum.WalkSpeed - 30
end)

Your force and speed are way too high, if the client were to receive the replication of the destruction of the body mover too late, they’ll get sent flying.

Since you only intend to apply the force for one frame, look into using BasePart:ApplyImpulse or BasePart.AssemblyLinearVelocity on the client, but if you wish to still use body movers / mover constraints, let the client handle the creation and removal of it.

1 Like

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