How do you make a script that makes your walkspeed go faster the longer you hold. For example:
after you hold W for 4 seconds the walkspeed go faster, and then you hold for 8 seconds, it goes faster.
If you play Touch Football you know what I mean.
1 Like
It’s pretty much easy. (This goes in StarterCharacterScripts, by the way.)
local maxSpeed = 65
local speedGain = 4
while task.wait() do
if script.Parent.Humanoid.MoveDirection == Vector3.new(0,0,0) then
script.Parent.Humanoid.WalkSpeed = 16
else
script.Parent.Humanoid.WalkSpeed = script.Parent.Humanoid.WalkSpeed + speedGain
if script.Parent.Humanoid.WalkSpeed >= maxSpeed then
script.Parent.Humanoid.WalkSpeed = maxSpeed
end
end
end
1 Like
I want it to be a delayed, for example: 5 seconds after u hold W, your walkspeed is 18, 8 seconds later after u keep holding W, your walkspeed is 23 like that
1 Like
Nvm I figured it out myself but thanks tho for helping a bit
local userInputService = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local step = 1 --increase walkspeed by 1 per second
--17 walkspeed after 1 second, 18 walkspeed after 2 seconds (longer you hold, faster you go)
local maxSpeed = 50 --maximum speed
local function onInputBegan(input, processed)
if processed then return end
if input.KeyCode ~= Enum.KeyCode.W then return end --check if W pressed
local connection
connection = runService.RenderStepped:Connect(function(delta)
if userInputService:IsKeyDown(Enum.KeyCode.W) then --check if W held
if humanoid.WalkSpeed > maxSpeed then return end
humanoid.WalkSpeed += (delta * step) --increase walkspeed
else
connection:Disconnect() --disconnect connection
humanoid.WalkSpeed = 16 --reset walkspeed
end
end)
end
userInputService.InputBegan:Connect(onInputBegan)
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.