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

How do I make a sprint button (pressing shift to sprint)?

Asked by 10 years ago

I am making a capture the flag game and I want to add a sprint button. I would also like it if I could have help making it so that you stop sprint after sprinting for x amount of time with a 1 second cool down.

0
function onPlayerEntered(player) 02 repeat wait () until player.Character ~= nil 03 local s = script.SprintScript:clone() 04 s.Parent = player.Character 05 s.Disabled = false 06 player.CharacterAdded:connect(function (char) 07 local s = script.SprintScript:clone() 08 s.Parent = char 09 s.Disabled = false 10 end) 11 end 12 13 game.Players.Playe moggieanne 0 — 5y

2 answers

Log in to vote
0
Answered by 10 years ago

Alright in workspace insert a script (not local)like this

function onPlayerEntered(player)
    repeat wait () until player.Character ~= nil
    local s = script.SprintScript:clone()
    s.Parent = player.Character
    s.Disabled = false
    player.CharacterAdded:connect(function (char)
        local s = script.SprintScript:clone()
        s.Parent = char
        s.Disabled = false      
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

Insert another script inside that one not the code but insert new script inside that one so the script becomes that scripts child and make sure its a local script

local mouse = game.Players.LocalPlayer:GetMouse()
local running = false

function getTool()  
    for _, kid in ipairs(script.Parent:GetChildren()) do
        if kid.className == "Tool" then return kid end
    end
    return nil
end


mouse.KeyDown:connect(function (key) -- Run function
    key = string.lower(key)
    if string.byte(key) == 48 then
        running = true
        local keyConnection = mouse.KeyUp:connect(function (key)
            if string.byte(key) == 48 then
                running = false
            end
        end)
        for i = 1,5 do
            game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
            wait()
        end
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 24
        repeat wait () until running == false
        keyConnection:disconnect()
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
        for i = 1,5 do
            game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))--Changes field of view sprint
            wait()
        end
    end
end)
Ad
Log in to vote
0
Answered by 3 years ago

Put a local script into your starter character scripts and put this in:

local inputservice = game:GetService("UserInputService")

inputservice.InputBegan:Connect(function(input, plr)

    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.LeftShift then
            script.Parent:WaitForChild("Humanoid").WalkSpeed = 60
        end
    end

end)

Answer this question