BodyVelocity Reversing upon the 2nd time?

What I am trying to make is make an ability that dashes forwards people and punches them.
The problem I am facing is that upon after using a ability for the 2nd time, the bodygyro literally reverses, I am not sure if this is a Roblox Bug or it’s somehow I am doing something wrong, it would be appreciated if anyone could help me!


First Time I use this ability: As you can see, it’s working perfectly and exactly how I want it.

Second time I use this ability: Then it starts to mess up, sometimes reversing and the aim completely off the rail. I have literally no idea what is making this happen.


Local Script (Module)

MOVE["Ability"] = function(Player, Character, RushValue, nameability, attacking, idk, debounce_name, debounce_delay, random)
	local humanoid = Character:WaitForChild("Humanoid")
	local Class = Player.Backpack[Player.Data.Class.Value]
	local ClassData = Player.Data.Class.Value
	local cooldown = game.ReplicatedStorage.Classes[ClassData].Moves[nameability]
	local mouse = Player:GetMouse()
	local root = Character.HumanoidRootPart
	local bodyvel_ing = false
	local initialcframe = root.CFrame
	local movevector = Vector3.new(0, 0, 0)
	
	
	local waiter = coroutine.wrap(function()
		if Character.Values.Stunned.Value == false then
			if RushEnabled == true then
				if debounce_name then
					RushValue.Value = true
					combat = true
					enabled = true
					wait()
					Class.Event:FireServer(Character, Character.HumanoidRootPart, humanoid, nameability, nameability, true, mouse.Hit)
					local gyro = Instance.new("BodyGyro",root)
					gyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
					gyro.P = 1000
					gyro.D = 300
					local bodyPosition = Instance.new("BodyPosition", root)
					bodyPosition.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
					bodyPosition.Position = root.Position	
					bodyPosition.P = 9000
					bodyPosition.D = 200	
					
					while enabled == true do
						wait()	
						gyro.CFrame = CFrame.new(root.Position,mouse.Hit.p)
						wait(.0001)
					end
				elseif not debounce_name and RushEnabled then
					RushValue.Value = false
					enabled = false
					RushEnabled = false
					wait()
					bodyvel_ing = true
					local thread1 = coroutine.wrap(function()
						game:GetService('RunService').Heartbeat:Connect(function()
							if bodyvel_ing == true then
								if (initialcframe.p - root.CFrame.p).magnitude >= 50 then
									movevector = Vector3.new(0, 0, 0)
									for i,v in pairs(root:GetChildren()) do
										if v:IsA("BodyVelocity") then
											v:Destroy()
											humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
											root.Anchored = true
											wait(.15)
											root.Anchored = false												
										end	
									end								
								end
							end
						end)
					end)
					thread1()
					Class.Event:FireServer(Character, Character.HumanoidRootPart, humanoid, nameability, nameability, false, mouse.Hit)
					combat = false
					wait(debounce_delay)
					bodyvel_ing = false
					debounce_name = true
					wait(cooldown.Value - idk)
					RushEnabled = true
				end
			end
		end	
	end)
	waiter()
end

Server Script

script.Parent.Event.OnServerEvent:Connect(function(player, char, root, humanoid, status, status2, status3, status4)
	if status == "[X] - Ability" then
		if status3 == true theen	
			enabled2 = true
			root.Anchored = true
			PunchedCharge:Play()
			PunchedCharge:GetMarkerReachedSignal("Charge"):Connect(function()
				PunchedCharge:AdjustSpeed(0)
			end)
		elseif status3 == false then
			humanoid.AutoRotate = false
			PunchedCharge:AdjustSpeed(1)
			
			local thread1 = coroutine.wrap(function()
				for i = 1,12 do
					effect_module['FX_Operator'](humanoidrootpart, player, vfx_general.ExpandFade,mesh_fx.CurvedRing, root.Parent, Vector3.new(.2,.2,.2), Color3.fromRGB(255, 255, 255), 1, 1, CFrame.new(0,0,-i / 2) * CFrame.Angles(math.rad(-90),0,0), 0, Vector3.new(23.365, 2.45, 23.365), 'Color3', false, root)
					wait(.1)
				end
			end)
			local thread2 = coroutine.wrap(function()
				for i = 1,6 do
					wait(.3)
					effect_module['FX_Operator'](humanoidrootpart, player, vfx_general.ExpandFade,mesh_fx.Crown, root.Parent, Vector3.new(39.441, 19, 39.441), Color3.fromRGB(255, 255, 255), 1, 1, CFrame.new(0,0,-2) * CFrame.Angles(math.rad(90),0,0), 0, Vector3.new(.2,.2,.2), 'Color3', false, root)					
					hitbox_module.AOE(character, character:WaitForChild('HitPart'), 15, 15, 1, false, 'baka', player, script.Parent.Hitbox)					
				end
			end)
			thread2()
			thread1()
            remotes.ClientGui:FireClient(player, "CoolDown", status2, status2)

			local y = Instance.new("BodyVelocity")
			y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
			y.Parent = root
			y.Velocity = CFrame.new(root.Position,status4.p).lookVector * 150
			game:GetService("Debris"):AddItem(y, .5)
			wait(.1)						
			root.Anchored = false
			wait(1)
			humanoid.AutoRotate = true
		end	
    end
end)

Is it possible that after using the ability once, invisible parts are lingering in workspace, which are clicked on without knowing, causing your character to go in the wrong direction?

You could test this out by placing a part at the mouse hit location, or by printing out various variables involved in the process of directing your character.

2 Likes

There’s an incorrect spelling on the 3rd code line in server script, perhaps that is what’s causing your problem?

1 Like

That was only a typo in the post, sorry!

After looking through my workspace and realizing the majority of my Effects stayed on and I forgot to use AddItem, after doing so it fixed my issue.

Thanks alot!

1 Like

Since you used the mouse as the direction where the user could charge at, it could be touching invisible hitboxes that caused strange directions, you can probably make some difference in the code where it’ll ignore these parts.