In my game I have multiple dashes/skills that have a dash combined with them. To create these dashes I use a Body Velocity in the Humanoid Root Part, but the only problem is if the player launches into any part they will fling and glitch. I have figured out a solution to this problem by using a render step connected with a touched event checking for a Body Velocity and deleting it then changing the Humanoid Root Part velocity to 0, but this creates major lag for the player anytime they touch anything. So I created a new script that still utilizes a value and remote event to enable the Render step with touched event, but disconnects the touch event after as well, but this script set up only has around 20% chance of actually working.
Local Script
wait(1)
Main = script.Parent.HumanoidRootPart
local RunService = game:GetService("RunService")
Bving = false
OnIt = false
event = script.Parent.BvEvent
local function onRenderStep(deltaTime)
if Bving == false then
if script.Parent.BvOn.Value == true then
Bving = true
Touching = Main.Touched:Connect(function(Part)
if Part.CanCollide == true then
Main.Velocity = Vector3.new()
Main.RotVelocity = Vector3.new()
event:FireServer()
end
end)
repeat wait()
until script.Parent.BvOn.Value == false
Touching:Disconnect()
Bving = false
end
end
end
RunService.RenderStepped:Connect(onRenderStep)
Server Script
wait(1)
event = script.Parent.BvEvent
Main = script.Parent.HumanoidRootPart
event.OnServerEvent:connect(function()
if script.Parent.BvOn.Value == true then
if Main:FindFirstChild("BV") then
Main:FindFirstChild("BV"):remove()
end
Main.Velocity = Vector3.new()
Main.RotVelocity = Vector3.new()
y = Instance.new("BodyVelocity")
y.Name = "BV"
y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
y.velocity = Main.CFrame.lookVector*0
y.Parent = Main
game.Debris:AddItem(y,0.001)
Main.Velocity = Vector3.new()
Main.RotVelocity = Vector3.new()
script.Parent.BvOn.Value = false
end
end)
Both scripts, the value, and the remote event are placed inside the Player Character for every player.