#How do i made the slide stay un till i un hold the button? and will speed up when slide down hills
18 messages · Page 1 of 1 (latest)
local UIS = game:GetService("UserInputService")
local char = script.Parent
local slideAnim = Instance.new("Animation")
local ca = rbxassetid -- keep your existing animation ID
local isSliding = false
UIS.InputBegan:Connect(function(input, gameprocessed)
if gameprocessed then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
isSliding = true
local playAnim = char.Humanoid:LoadAnimation(slideAnim)
playAnim:Play()
while isSliding do
local rayOrigin = char.HumanoidRootPart.Position
local rayDirection = Vector3.new(0, -10, 0)
local ray = Ray.new(rayOrigin, rayDirection)
local hitPart, hitPoint, hitNormal = workspace:FindPartOnRay(ray)
if hitPart then
-- Calculate slope angle
local slopeAngle = math.acos(hitNormal.Y)
local slopeMultiplier = math.sin(slopeAngle) * 2
local slide = script.Slide
slide.Parent = char.HumanoidRootPart
slide.MaxForce = Vector3.new(1,0,1) * 10000
-- Base velocity plus slope adjustment
local baseVelocity = 0.7
slide.Velocity = char.HumanoidRootPart.CFrame.LookVector *
(baseVelocity + slopeMultiplier)
end
task.wait(0.1)
end
end
end)
UIS.InputEnded:Connect(function(input, gameprocessed)
if gameprocessed then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
isSliding = false
if char.HumanoidRootPart:FindFirstChild("Slide") then
char.HumanoidRootPart.Slide:Destroy()
end
end
end)```
ty
Did it work?
FindPartOnRay is deprecated https://create.roblox.com/docs/reference/engine/classes/WorldRoot#FindPartOnRay
this makes it only work once lua local slide = script.Slide slide.Parent = char.HumanoidRootPart
should be a clone instead of directly moving it
alternatively use instance.new
thanks it work now
also also lua local playAnim = char.Humanoid:LoadAnimation(slideAnim) playAnim:Play() should only load the animation once, this loads it each time.
also the stop sliding doesnt stop playing this animation
Fix it Pyro 👍
homework for @harsh spindle