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

Can someone help me with this combined sprint (shift and double tap w) script?

Asked by
d512634 10
10 years ago

I tried to combine minecraft sprint script and shift sprint script but there's a problem. It screws up my walkspeed and the camera's field of view when i did both double tapping w and holding shift and release w before releasing shift.

I've removed the animations the script gave me, renamed the variables and added more conditions to separate both functions but it doesn't seem to work.

It'l be nice if someone can fix it.

And here's the script:

local mouse = game.Players.LocalPlayer:GetMouse()
local wrunning = false
local shiftrunning = false
local s = ""

mouse.KeyDown:connect(function (key)
    key = string.lower(key)
    if (key == "w" or key == "") and string.byte(key) ~= 48 then
        s = s.."w"
        delay(0.2,function ()
            if s ~= "ww" then
                s = ""
            end
        end)
        if s == "ww" then
            s = ""
            wrunning = true
            local wkeyConnection = mouse.KeyUp:connect(function (key)
                if key == "w" or key == "" then
                    wrunning = false
                end
            end)
            local fov = game.Workspace.CurrentCamera.FieldOfView
            for i = 1,5 do
                game.Workspace.CurrentCamera.FieldOfView = (fov+(i*2))
                wait()
            end
            local walkspeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed
            game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = walkspeed +8
            repeat wait () until wrunning == false
            wkeyConnection:disconnect()
            game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = walkspeed
            for i = 1,5 do
                game.Workspace.CurrentCamera.FieldOfView = (fov+10-(i*2))
                wait()
            end
        end
    end
    if string.byte(key) == 48 and key ~= "w" then
        shiftrunning = true
        local shiftkeyConnection = mouse.KeyUp:connect(function (key)
            if string.byte(key) == 48 then
                shiftrunning = false
            end
        end)
        local fov = game.Workspace.CurrentCamera.FieldOfView
        for i = 1,5 do
            game.Workspace.CurrentCamera.FieldOfView = (fov+(i*2))
            wait()
        end
        local walkspeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = walkspeed + 8
        repeat wait () until shiftrunning == false
        shiftkeyConnection:disconnect()
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = walkspeed
        for i = 1,5 do
            game.Workspace.CurrentCamera.FieldOfView = (fov+10-(i*2))
            wait()
        end
    end
end)

Thanks.

1 answer

Log in to vote
0
Answered by 10 years ago

Try this.

local mouse = game.Players.LocalPlayer:GetMouse()
local wrunning = false
local shiftrunning = false
local runningSetUp = false
local s = ""

local fovIncrease = 10
local walkspeedIncrease = 8

local toggleDebounce = false
function toggleRunning()
    if toggleDebounce then return end
    toggleDebounce = true
    if wrunning or shiftrunning then
        if runningSetUp then return end
        game.Workspace.CurrentCamera.FieldOfView = game.Workspace.CurrentCamera.FieldOfView + fovIncrease
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed + walkspeedIncrease
        runningSetUp = true
    else
        if not runningSetUp then return end
        game.Workspace.CurrentCamera.FieldOfView = game.Workspace.CurrentCamera.FieldOfView - fovIncrease
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed - walkspeedIncrease
        runningSetUp = false
    end
    toggleDebounce = false
end

mouse.KeyDown:connect(function (key)
    key = string.lower(key)
    if (key == "w" or key == "") and string.byte(key) ~= 48 then
        s = s.."w"
        delay(0.2,function ()
            if s ~= "ww" then
                s = ""
            end
        end)
        if s == "ww" then
            s = ""
            wrunning = true
            local wkeyConnection
            wkeyConnection = mouse.KeyUp:connect(function (key)
                if key == "w" or key == "" then
                    wrunning = false
                    wkeyConnection:disconnect()
                    toggleRunning()
                end
            end)
        end
    end
    if string.byte(key) == 48 and key ~= "w" then
        shiftrunning = true
        local shiftkeyConnection = mouse.KeyUp:connect(function (key)
            if string.byte(key) == 48 then
                shiftrunning = false
            end
        end)
    end
    toggleRunning()
end)
0
This doesn't work for me. And I couldn't see what's problem this script has. The output said nothing. d512634 10 — 10y
Ad

Answer this question