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
5 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 — 5y
1
Could you please edit your question and add codeblocks, thank you. herrtt 387 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
01UIS.InputBegan:connect(function(input)
02On = false
03 if input.KeyCode == Enum.KeyCode.LeftControl then
04    If On == false then
05        On = true
06         While on do
07                Wait()
08         Character.Humanoid.WalkSpeed = 25
09          --- Load animation and stuff
10     else
11           print ("Stopped running")
12     end
13end

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 5 years ago
Edited 5 years ago

All you needed to add was a toggle:

01local UIS = game:GetService("UserInputService")
02 
03local toggle = false
04 
05local player = game.Players.LocalPlayer
06 
07local Character = player.Character
08 
09UIS.InputBegan:Connect(function(input, gameProcessedEvent)
10 
11    if input.KeyCode == Enum.KeyCode.LeftControl then
12        if toggle == false then
13            toggle = true
14            Character.Humanoid.WalkSpeed = 25
15            local Anim = Instance.new("Animation")
View all 28 lines...

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