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

So when i run my roll script it works. But when I jump and use it sends the plr flying?

Asked by
Tan0ak 28
4 years ago
Edited 4 years ago

Can someone help me?

all the code is in a local script and is put in the starter character scripts.

local UIS = game:GetService('UserInputService')
local Anim = game.StarterPack.ClassicSword:WaitForChild('RollAnim')
local plr = game.Players.LocalPlayer.Character
local cooldown = false

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.R and cooldown == false then
        local Animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(Anim)
        Animation:Play()
        plr.HumanoidRootPart.Velocity += plr.HumanoidRootPart.CFrame.lookVector*150
        cooldown = true
        wait(.7)
        cooldown = false

    end

end)

https://gfycat.com/merryultimateegret the link is for the video

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try using Humanoid:MoveTo. Usually, it walks to the place you input but you have a "Roll" animation overwriting that.

local UIS = game:GetService('UserInputService")
local CAS = game:GetService("ContextActionService")
local Anim = game.StarterPack.ClassicSword:WaitForChild('RollAnim')
local plr = game.Players.LocalPlayer
local char = plr.Character
local cooldown = false
local targetArea, previousSpeed

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.R and not cooldown then
        cooldown = true
        local Animation = Char.Humanoid:LoadAnimation(Anim)
        Animation:Play()
        previousSpeed = Char.Humanoid.WalkSpeed -- Get previous speed
        Char.Humanoid.WalkSpeed = 150/Animation.Length -- Set speed
        targetArea = Vector3.new(Char.HumanoidRootPart.CFrame.lookVector.X*150, Char.HumanoidRootPart.CFrame.lookVector.Y*150, Char.HumanoidRootPart.CFrame.lookVector.Z*150) -- Set target area
        Char.Humanoid:MoveTo(targetArea) -- MOVE MOVE MOVE
        ContextActionService:BindAction( -- Freeze player
            "freezeMovement",
            function() return Enum.ContextActionResult.Sink end,
            false,
            unpack(Enum.PlayerActions:GetEnumItems())
        )
        Char.Humanoid.MoveToFinished:Connect(function(reached) -- Wait until finished
            Char.Humanoid.WalkSpeed = previousSpeed  -- Set to previous speed
            ContextActionService:UnbindAction("freezeMovement") -- Unfreeze player
        end)
        wait(.7)
        cooldown = false
    end
end)

You can see the comments for an explanation

Ad

Answer this question