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 11 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 — 6y

2 answers

Log in to vote
0
Answered by 11 years ago

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

01function 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)
11end
12 
13game.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

01local mouse = game.Players.LocalPlayer:GetMouse()
02local running = false
03 
04function getTool() 
05    for _, kid in ipairs(script.Parent:GetChildren()) do
06        if kid.className == "Tool" then return kid end
07    end
08    return nil
09end
10 
11 
12mouse.KeyDown:connect(function (key) -- Run function
13    key = string.lower(key)
14    if string.byte(key) == 48 then
15        running = true
View all 34 lines...
Ad
Log in to vote
0
Answered by 3 years ago

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

01local inputservice = game:GetService("UserInputService")
02 
03inputservice.InputBegan:Connect(function(input, plr)
04 
05    if input.UserInputType == Enum.UserInputType.Keyboard then
06        if input.KeyCode == Enum.KeyCode.LeftShift then
07            script.Parent:WaitForChild("Humanoid").WalkSpeed = 60
08        end
09    end
10 
11end)

Answer this question