✓ Accepted answer
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
local Input = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local dashEvent = RS:FindFirstChild("DashEvent")
local lastKey = false
local lastClick
local DASH_TIME = .5
Input.InputBegan:connect(function(KeyInput)
if KeyInput.KeyCode == Enum.KeyCode.W then
if not lastKey then
lastKey = true
end
if lastClick ~= nil and tick() - lastClick <= DASH_TIME then
print("Dash")
dashEvent:FireServer(true)
lastKey = false
else
lastClick = tick()
end
end
end)
Input.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
print("LIFTED")
dashEvent:FireServer(false)
end
end)
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.
local RS = game:GetService("ReplicatedStorage")
local dashEvent = RS:FindFirstChild("DashEvent")
local SPEED_INC = 100
local NORMAL = 16
local function SpeedAdjust (player, runningBool)
local hum = player.Character:WaitForChild("Humanoid")
if hum and runningBool then
print("SPRINT")
hum.WalkSpeed = hum.WalkSpeed + SPEED_INC
elseif hum and not runningBool then
print("SLOW")
hum.WalkSpeed = NORMAL
end
end
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 :)
2 comments
thats a remote event lol
Nani? (I'm confused...)