How would I change the direction of a roll script?

I have watched a tutorial on how to make a sliding script but I want to modify it to be a rolling script.
This is the script I have currently,

local UIS = game:GetService("UserInputService")
local char = script.Parent

local slideAnim = Instance.new("Animation")
slideAnim.AnimationId = "rbxassetid://6674169146"

local keybind = Enum.KeyCode.LeftControl
local canslide = true

UIS.InputBegan:Connect(function(input,gameprocessed)
	if gameprocessed then return end
	if not canslide then return end
	
	if input.KeyCode == keybind then
		canslide = false
		
		local playAnim = char.Humanoid:LoadAnimation(slideAnim)
		playAnim:Play()
		
		local slide = Instance.new("BodyVelocity")
		slide.MaxForce = Vector3.new(1,0,1) * 30000
		slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 50
		slide.Parent = char.HumanoidRootPart
		
		for count = 1, 8 do
			wait(0.1)
			slide.Velocity*= 0.7
		end
		playAnim:Stop()
		slide:Destroy()
		canslide = true
	end
end)

I do not know too much information about CFrames or BodyGyros so if anybody can help me out it would be appreciatted.
I am guessing the line I have to modify is this one

slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 50

But I don’t know how to make it so that it moves to the right/left

I’m confused on what you’re trying to do. At the moment your rolling script will send you towards the direction you’re facing, what are you trying to accomplish? Your rolling script will go right and left as long as you’re facing the direction.

Well, I want it to send you strictly to the left, and I want to to send you to the left of your characters look direction(i don’t know if that made sense) but I am guessing that if I try to use CFrame.X it will send you into the left of the worlds direction instead of the left of your character look direction

1 Like

Left Roll:

slide.Velocity = (char.HumanoidRootPart.CFrame * CFrame.Angles(0,math.pi / 2,0)).lookVector * 50

Right Roll:

slide.Velocity = (char.HumanoidRootPart.CFrame * CFrame.Angles(0,-math.pi / 2,0)).lookVector * 50
3 Likes

Thank you for the response! It worked! But I am wondering what does math.pi do in this script?

2 Likes

It is 360 angles of movement. It chooses the positive when pi is divided, and negative when negative pi is divided.

1 Like

pi / 2 is equivalent to 90 degrees. It’s rotating the frontward facing direction 90 degrees to the left/right.

1 Like