hello! this is my first post so pls lmk if anything is wrong
what i want to achieve:
I want to make my player move forward when they press the X key, and i want their speed to be 22, and then after 5 seconds they stop moving forward and cannot move for 3 seconds. I believe that i can script the stop moving part, but I dont know how to script this “charge” script
the issue:
I am not sure what to do to create this, I haven’t been able to find anything discussing something similar to this
what i’ve done to fix:
I’ve tried looking on the forum for anybody trying to make something like this, but I haven’t found anything.
if theres any sort of function or mechanic i should know to code this please lmk!
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Disable default controls
local controls = require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls()
controls:Disable()
-- Settings
local speed = 22
local bool = false
-- Setup
humanoid.WalkSpeed = speed
local function updateMovement()
local moveDirection = Vector3.new(0, 0, 0)
if UserInputService:IsKeyDown(Enum.KeyCode.X) then
moveDirection = Vector3.new(0, 0, -1)
if not bool then
bool = true
task.delay(5, function()
print("can't move")
humanoid.WalkSpeed = 0
wait(3)
print("can move")
humanoid.WalkSpeed = speed
end)
end
end
humanoid:Move(moveDirection, true)
end
UserInputService.InputBegan:Connect(updateMovement)
UserInputService.InputEnded:Connect(updateMovement)
also, just to let you know, this would not allow the player to move once again after the charge is ended, i just added controls:Enable() after the humanoid.WalkSpeed string before the script ends, i dont believe i communicated this but i still appreciaate the script!