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

How do I make the player run faster after pressing a button?

Asked by 3 years ago

How would I make the player run fast/start sprinting when they hold down the shift key?

2 answers

Log in to vote
0
Answered by 3 years ago

Insert a RemoveEvent in the workspace and name it ServerChange. Place a script inside and type these lines:

script.Parent.OnServerEvent:Connect(function(Nothing, Item, Property, Val)
    Item[Property] = Val
end)

Insert another LocalScript into StarterGui and type these lines:

game:GetService("UserInputService").InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        workspace.ServerChange:FireServer(game.Players.LocalPlayer.Character.Humanoid, "WalkSpeed", 20)
    end
end)

Hope this helped send a comment if it didn't

0
Do not use RemoteEvents like that because exploiters can exploit the game with that. You can also just set the WalkSpeed on the client. COUNTYL1MITS 312 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Or Just make an easier script like this:

local uis = game:GetService("UserInputService") --Search for UserInput Service

uis.InputBegan:Connect(key)
    if key.KeyCode == Enum.KeyCode.LeftShift then --If LeftShift Pressed, then Player speed = 25
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
    end
end)

uis.InputEnded:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.LeftShift then --If LeftShift Press Ended, then Player speed = 16
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
    end
end)

Answer this question