Player is going zoooom from the linear velocity

The player is basically moving at light speed for the first second and then slows down to a snails pace

local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:FindFirstChild("Humanoid")
local runanim = hum:LoadAnimation(script.RunAnim)
local root = char:FindFirstChild("HumanoidRootPart")
runanim.Priority = Enum.AnimationPriority.Action
local function activate()
	game.ReplicatedStorage.Remotes.Cyborgs.RunningBlast:FireServer(char,root,hum)
	runanim:Play()
	game["Run Service"].RenderStepped:Connect(function(frame)
		local BV = Instance.new("LinearVelocity")
		BV.Parent = root
		BV.Attachment0 = root.RootAttachment
		BV.MaxForce = 100000
		BV.VectorVelocity = 100000 * root.CFrame.LookVector
		game:GetService("Debris"):AddItem(BV, frame)
	end)
end
script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
	activate()
end)

2 Likes

Okay so, is the part that is inside the player
CanCollide = false
Massless = true
Because if these properties are not the same as i just said, it might be causing some issues.

1 Like

if you mean the attachment0 then its literally just the humanoid root part

1 Like

Umm, I didn’t quite understand what you said, I mean the part that you’ve spawned with a script that
is following the player

1 Like

ohhh i get it now, you’re talking about in the video, yea that part is just a hitbox, i tried removing the code that spawned it before i made this post and nothing changed

1 Like

Oh, Alright i think instead of using LinearVelocity it would be better to use BodyVelocity since even
if you get LinearVelocity working it still has some problems of its own. Here is a basic example of using this

local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(1,0,1) * 30000
BV.Velocity = root.CFrame.lookVector * 110
BV.Parent = root

task.spawn(function() --this makes it so the player doesnt just zoooom off the map
	for count = 1, 8 do
		task.wait(0.1)
		slide.Velocity *= 0.7
	end
	BC:Destroy()
end)

I haven’t tested it so i don’t know if it works, but it should work since it use it in my other projects.

1 Like

it doesnt work, im going insane

2 Likes

The same problem is happening?

2 Likes

well its kinda just the same thing as before, except everything is lowered

2 Likes

Can i ask what the slide variable is?

2 Likes

Oh, mb i forgot you have to change the slide to BV and BC to BV at the part where is does :Destroy()
i forgot to change that, lol

2 Likes

I tried that earlier i just wanted to know if slide was a seperate variable

1 Like

Well slide isn’t a seperate variable

2 Likes

If your code does not work, a better place to ask this would be Scripting Support rather than Code Review.

Code Review is intended for improving already working code.

2 Likes

You should not be creating a new linear velocity every frame. Instead, create one linear velocity and update the properties (e.g. change the velocity direction or change whether it’s enabled.

The problem here I bet is that:

  • First: Your velocity is insanely fast :sweat_smile:. A character walks at 16 studs per second by default. Your velocity is 100,000 studs per second.
  • Second: When you create two linear velocities with different directions (b|c you make one every frame), the linear velocities probably use all their force to cancel each other out.

Note that Debris only roughly destroys the item at the correct time, so you shouldn’t rely on it to destroy the object at exactly the right time.


Perhaps try something like this:

local player = game.Players.LocalPlayer
local char = player.Character
local hum = char:FindFirstChild("Humanoid")
local runanim = hum:LoadAnimation(script.RunAnim)
local root = char:FindFirstChild("HumanoidRootPart")
runanim.Priority = Enum.AnimationPriority.Action

local isActive = false
local function activate()
	-- Only activate if not already active
	if isActive then return end

	game.ReplicatedStorage.Remotes.Cyborgs.RunningBlast:FireServer(char,root,hum)


	-- Start the run animation
	runanim:Play()

	-- Create a LinearVelocity
	local BV = Instance.new("LinearVelocity")
	BV.Parent = root
	BV.Attachment0 = root.RootAttachment
	BV.MaxForce = 100000

	-- Update the velocity direction every frame
	local connection = game:GetService("RunService").RenderStepped:Connect(function(frame)
		BV.VectorVelocity = 32 * root.CFrame.LookVector
	end)

	-- Optional: End the dash after 5 seconds
	--task.wait(5)
	--connection:Disconnect()
	--BV:Destroy()
	--isActive = false  -- Reset the debounce so it can be used again
end
script.Parent.Parent.TextButton.MouseButton1Click:Connect(function()
	activate()
end)
1 Like