How to prevent rolling script from fling player?

I am trying to make a directional rolling script, and it works fine except for one thing.

Whenever the player rolls into a wall or something, they get knocked over or flung.

This script uses a BodyVelocity, if that helps.

local script:

local UserInputService = game:GetService("UserInputService")

local Character = script.Parent
local Root = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")

local Sound = game:GetService("SoundService"):WaitForChild("Roll")

local RollAnim = script:WaitForChild("RollAnimation")
local RollTrack = Humanoid:LoadAnimation(RollAnim)

local RightAnim = script:WaitForChild("RightAnimation")
local RightTrack = Humanoid:LoadAnimation(RightAnim)

local LeftAnim = script:WaitForChild("LeftAnimation")
local LeftTrack = Humanoid:LoadAnimation(LeftAnim)

local BackAnim = script:WaitForChild("BackAnimation")
local BackTrack = Humanoid:LoadAnimation(BackAnim)

canRoll = true

local function ToWalkRelativeToHRP(Humanoid, Direction, RootCompare)

		local RootFacing = RootCompare.CFrame.LookVector
		local RootRight = RootCompare.CFrame.RightVector

		local DirectionRelativeToRootFront = RootFacing:Dot(Direction, RootFacing)
		local DirectionRelativeToRootSides = RootRight:Dot(Direction, RootRight)
		----

		local Output = nil

		if DirectionRelativeToRootFront <= 1 and DirectionRelativeToRootFront >= 0.75 then
			Output = "Forwards"
		elseif DirectionRelativeToRootFront >= -1 and DirectionRelativeToRootFront <= -0.75 then
			Output = "Backwards"
		elseif DirectionRelativeToRootSides <= 1 and DirectionRelativeToRootSides >= 0.75 then
			Output = "Right"
		elseif DirectionRelativeToRootSides >= -1 and DirectionRelativeToRootSides <= -0.75 then
			Output = "Left"
		end

	return Output
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end
	if input.KeyCode == Enum.KeyCode.Q and canRoll == true then
		canRoll = false
		script:WaitForChild("OnRoll"):FireServer(Character:WaitForChild("Right Leg"), Character:WaitForChild("Left Leg"), true)
		local BV = Instance.new("BodyVelocity")
		BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		if Humanoid.MoveDirection == Vector3.new(0,0,0) then
			BV.Velocity = Root.CFrame.LookVector * 30
		else
			BV.Velocity = Vector3.new(Humanoid.MoveDirection.X, 0, Humanoid.MoveDirection.Z) * 30
		end
		local ForceVector = ToWalkRelativeToHRP(Humanoid, Humanoid.MoveDirection, Root)
		if ForceVector == "Forwards" then
			RollTrack:Play()
		elseif ForceVector == "Backwards" then
			BackTrack:Play()
		elseif ForceVector == "Right" then
			RightTrack:Play()
		elseif ForceVector == "Left" then
			LeftTrack:Play()
		elseif ForceVector == nil then
			RollTrack:Play()
		end
		BV.Parent = Root
		Sound:Play()
		task.wait(.5)
		script:WaitForChild("OnRoll"):FireServer(Character:WaitForChild("Right Leg"), Character:WaitForChild("Left Leg"), false)
		BV:Destroy()
		task.wait(.5)
		canRoll = true
	end
end)
1 Like

Could you send a video of the player being flung?

It’s not flung, but it’s just that when they roll directly into a wall they get knocked over.

The following part is the issue:

Have a maximum, you have to test around with this anywhere from 100 to 100000

BV.MaxForce = Vector3.one * 100
2 Likes

This didn’t work for me, it made the player actually fling, they went like 600 studs in the air when they rolled directly into a wall.