Need assistance with getting a Sliding ability to work

I’m trying to figure out how to make it so whenever the players presses a LeftShift, they will slide in a specific direction.

Unfortunately I keep on running into this specific issue where it gives me this bug

I’ve used many different methods and sources in order to get a sliding script to work but it always comes down to the HumanoidRootPart, in some way shape or form.

This is the code I’ve been using, and the script is also located in the StarterPlayerScripts folder.

local UIS = game:GetService("UserInputService")
local keybind = Enum.KeyCode.LeftShift
local canroll = true
local player = game:GetService('Players').LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local HumanoidRootPart = char:WaitForChild('HumanoidRootPart')

UIS.InputBegan:Connect(function(input,gameProcessed)
	if gameProcessed then return end
	if not canroll then return end
	
	if input.KeyCode == keybind then
		canroll = false
		
		local roll = Instance.new("BodyVelocity")
			roll.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			roll.Velocity = char.HumanoidRootPart.Cframe.lookVector * 100
			roll.Parent = char.HumanoidRootPart
		
		for count = 1, 8 do
			wait(0.1)
			roll.velocity *= 0.7
		end
		roll:Destroy()
		canroll = true
	end
end)

2 Likes

you misspelled CFrame as Cframe

4 Likes

I think you’re having trouble accessing the HumanoidRootPart, oh and can you please spell Cframe to CFrame? Lua is case sensitive.

Anyway, here’s the edited code:

local UIS = game:GetService("UserInputService")
local keybind = Enum.KeyCode.LeftShift
local canroll = true
local player = game:GetService('Players').LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local HumanoidRootPart = char:WaitForChild('HumanoidRootPart')

UIS.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end
    if not canroll then return end

    if input.KeyCode == keybind then
        canroll = false

        local roll = Instance.new("BodyVelocity")
        roll.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        roll.Velocity = HumanoidRootPart.CFrame.lookVector * 100 -- Calculate velocity based on lookVector
        roll.Parent = HumanoidRootPart

        for count = 1, 8 do
            wait(0.1)
            roll.Velocity = roll.Velocity * 0.7
        end
        roll:Destroy()
        canroll = true
    end
end)

I haven’t tested it yet, but if it does work, mark this as a solution.

2 Likes

Oh, my bad. Welp, that fixed it. Thank you for your help anyway. I’ll make sure to look out for even more spelling mistakes later on.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.