Answered by
6 years ago Edited 6 years ago
You have the right idea for the most part!
The reason using two InputBegan:Connect()'s isn't working is because it's just checking 2 times if W is pressed. Not checking if W is pressed, 2 times. Anyway
To achieve this I would use:
- Local Script in StarterPlayerScripts
- Remote Event in ReplicatedStorage named "DashEvent"
- Script in ServerScriptService named "DashScript"
First starting with the Local Script
02 | local Input = game:GetService( "UserInputService" ) |
03 | local RS = game:GetService( "ReplicatedStorage" ) |
05 | local dashEvent = RS:FindFirstChild( "DashEvent" ) |
12 | Input.InputBegan:connect( function (KeyInput) |
14 | if KeyInput.KeyCode = = Enum.KeyCode.W then |
20 | if lastClick ~ = nil and tick() - lastClick < = DASH_TIME then |
23 | dashEvent:FireServer( true ) |
33 | Input.InputEnded:Connect( function (input) |
34 | if input.KeyCode = = Enum.KeyCode.W then |
36 | dashEvent:FireServer( false ) |
Now with your local script set up, I've placed a Script in ServerScriptService called "DashScript"
Pretty Straight forward, at the bottom we listen for the Event to Fire and run the Speed Adjust function when it does. Like we saw in the local script, SpeedAdjust is getting 2 arguments, the player and the runningBool.
01 | local RS = game:GetService( "ReplicatedStorage" ) |
02 | local dashEvent = RS:FindFirstChild( "DashEvent" ) |
07 | local function SpeedAdjust (player, runningBool) |
08 | local hum = player.Character:WaitForChild( "Humanoid" ) |
09 | if hum and runningBool then |
11 | hum.WalkSpeed = hum.WalkSpeed + SPEED_INC |
12 | elseif hum and not runningBool then |
14 | hum.WalkSpeed = NORMAL |
19 | dashEvent.OnServerEvent:Connect(SpeedAdjust) |
There might be a better way to do the stop sprinting stuff but this works just fine. Let me know if you have any questions and don't forget to accept the answer if it helps you out :)