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

i wanna make it so when i'm not holding it stops but it still running fast - ?

Asked by 6 years ago
Edited 6 years ago
local UserInpServ = game:GetService('UserInputService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
UserInpServ.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.E then 
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 72
    else
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
    end
end)
-- help

0
Please format with a code block. xAtom_ik 574 — 6y
0
done i need to go right now sorry, byee xxrubucsxx 0 — 6y

1 answer

Log in to vote
0
Answered by
xAtom_ik 574 Moderation Voter
6 years ago

Formatting your code

Firstly, I formatted your code in a code block for you.

local UserInpServ = game:GetService('UserInputService') 
local ReplicatedStorage = game:GetService('ReplicatedStorage') 

UserInpServ.InputBegan:Connect(function(Input) 
    if Input.KeyCode == Enum.KeyCode.E then 
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 72 
    else 
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25 
    end 
end)

The issue

Basically, you need to check if the keycode was E when the input ends, which will detect that it was held and you can set the walkspeed back.

Here is a fixed script

local UserInpServ = game:GetService('UserInputService') 
local ReplicatedStorage = game:GetService('ReplicatedStorage') 

UserInpServ.InputBegan:Connect(function(Input) 
    if Input.KeyCode == Enum.KeyCode.E then 
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 72 
    end
end)

UserInpServ.InputEnded:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.E then
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
    end
end)

Thanks

Thanks for reading, hope I helped.

:-)

Ad

Answer this question