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)
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.