Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Slide Mechanic is Stuck. How do I fix this?

Asked by 2 years ago

I've been trying to implement this slide mechanic. For some reason, the animation & velocity doesn't stop.

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait() -- Index the current character, or grab the one from CharacterAdded when that event fires.

local InputService = game:GetService("UserInputService")
local animation = Instance.new("Animation")
local slidepossible = true


animation.AnimationId = "rbxassetid://9168644824"

wait(0.25) -- waiting for stuff to load
local playAnim = char.Humanoid:LoadAnimation(animation)
local slide = Instance.new("BodyVelocity")


InputService.InputBegan:Connect(function(key,gameprocessed)
    if gameprocessed then return end
    if not slidepossible then return end
    if key.KeyCode == Enum.KeyCode.LeftControl then
        if not _G.running then
            slidepossible = false
            local playAnim = char.Humanoid:LoadAnimation(animation)
            playAnim:Play()

            local slide = Instance.new("BodyVelocity")
            slide.MaxForce = Vector3.new(1,0,1) * 30000
            slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 100
            slide.Parent = char.HumanoidRootPart

        for count = 1,8 do
                wait(0.1)
                slide.Velocity *=0.7
            end
        end
    end
end)


InputService.InputEnded:Connect(function(key,gameprocessed)
    if gameprocessed then return end
    if key.KeyCode == Enum.KeyCode.LeftControl or Enum.KeyCode.Right then
        playAnim:Stop()
        wait()
        slide:Destroy("BodyVelocity")
        canslide = true    
    end

There are no errors and no output whatsoever. https://streamable.com/16okxg

0
Hey I spotted something, I spotted you where using "BodyVelocity" which Is Deprecated (Meaning It will no longer function when your making It In new work (Which means using It for new stuff ex. Models,Tools,etc.)) I would recommend using "VectorForce" (Heres A link to It: https://developer.roblox.com/en-us/api-reference/class/VectorForce) (NOTE: You also need to put a attachment to the torso or an imnotaguest1121 362 — 2y
0
How would you go about that? I'm a relatively new to scripting and roblox studio in general. I'm not sure how to insert an attachment into the player. aquoric 0 — 2y

Answer this question