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

I want to make a "Tap ,left control to sprint" but it is making me hold left control instead?

Asked by
Roguzy 2
4 years ago

i know a simple script but i guess i just forgot the basics or something `local UIS = game:GetService("UserInputService") local player = game.Players.LocalPlayer local Character = player.Character

UIS.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftControl then Character.Humanoid.WalkSpeed = 25 local Anim = Instance.new("Animation") Anim.AnimationId = "rbxassetid://04981880688" --You Animation local PlayAnim = Character.Humanoid:LoadAnimation(Anim) PlayAnim:Play() end end)

UIS.InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftControl then Character.Humanoid.WalkSpeed = 16 local Anim = Instance.new("Animation") Anim.AnimationId = "rbxassetid://04981880688" local PlayAnim = Character.Humanoid:LoadAnimation(Anim) PlayAnim:Stop() end end)

here is the script i want to be able to tap left control and sprint however it makes me hold left control which is what i dont want

1
Next time, use codeblocks to present code. DemonHunterz6 35 — 4y
1
Could you please edit your question and add codeblocks, thank you. herrtt 387 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
UIS.InputBegan:connect(function(input)
On = false
 if input.KeyCode == Enum.KeyCode.LeftControl then 
    If On == false then
        On = true
         While on do
                Wait()
         Character.Humanoid.WalkSpeed = 25
          --- Load animation and stuff
     else 
           print ("Stopped running")
     end
end

Try this, it has errors cause am trying on mobile and indenting wierd and annoys me so it not the full script... it a method I used to make a toggle for a text button... just fix the errors up since u said u already know some stuff

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

All you needed to add was a toggle:

local UIS = game:GetService("UserInputService")

local toggle = false

local player = game.Players.LocalPlayer

local Character = player.Character

UIS.InputBegan:Connect(function(input, gameProcessedEvent)

    if input.KeyCode == Enum.KeyCode.LeftControl then
        if toggle == false then
            toggle = true
            Character.Humanoid.WalkSpeed = 25
            local Anim = Instance.new("Animation")
            Anim.AnimationId = "rbxassetid://04981880688"
            local PlayAnim = Character.Humanoid:LoadAnimation(Anim)
            PlayAnim:Play()
        else
            toggle = false
            Character.Humanoid.WalkSpeed = 16
            local Anim = Instance.new("Animation")
            Anim.AnimationId = "rbxassetid://04981880688"
            local PlayAnim = Character.Humanoid:LoadAnimation(Anim)
            PlayAnim:Stop()
        end
    end
end)

Oh, and make sure this is in a local-script, and try to put this in StarterPlayer --> StarterPlayerScripts (not sure about this). Forgive my messy code.

Answer this question