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

Cannot hold any items while sprinting?

Asked by
VVaffly -3
6 years ago

I need it so that when the player is running, they cannot hold any items, please help.

Here is my script.

local Player = game.Players.LocalPlayer
    local Character = workspace:WaitForChild(Player.Name)
        local Humanoid = Character:WaitForChild('Humanoid')

local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://1683094860'
RAnimation = Humanoid:LoadAnimation(RunAnimation)

Running = false

function Handler(BindName, InputState)
    if InputState == Enum.UserInputState.Begin and BindName == 'RunBind' then
        Running = true
        Humanoid.WalkSpeed = 22
    elseif InputState == Enum.UserInputState.End and BindName == 'RunBind' then
        Running = false
        if RAnimation.IsPlaying then
            RAnimation:Stop()
        end
        Humanoid.WalkSpeed = 13
    end
end

Humanoid.Running:connect(function(Speed)
    if Speed >= 10 and Running and not RAnimation.IsPlaying then
        RAnimation:Play()
        Humanoid.WalkSpeed = 22
    elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
        RAnimation:Stop()
        Humanoid.WalkSpeed = 13
    elseif Speed < 10 and RAnimation.IsPlaying then
        RAnimation:Stop()
        Humanoid.WalkSpeed = 13
    end
end)

Humanoid.Changed:connect(function()
    if Humanoid.Jump and RAnimation.IsPlaying then
        RAnimation:Stop()
    end
end)

game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode.LeftShift)

Answer this question