Hello, I have a question, how can I make the script that when I press CTRL stays blocked, for example, when I press CTRL the character runs but I have to keep it pressed, how can I only touch it without having to leave it pressed?
The Script:
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
local runSpeed = 48 – Run Speed
– Function to make the character run
local function startRunning()
humanoid.WalkSpeed = runSpeed
end
– Function to stop the character from running
local function stopRunning()
humanoid.WalkSpeed = 16 – Normal Speed
end
– Event connections
game:GetService(“UserInputService”).InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
startRunning()
end
end)
game:GetService(“UserInputService”).InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
stopRunning()
end
end)
if you are talking about a toggle system, you could simply update a boolean to be NOT equal to itself every time an input begins
also, please make a variable for UIS. So that roblox will not have to get it every time
I have provided some EXAMPLE code below:
game:GetService(“UserInputService”).InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
running = not running
end
You could use RunService to solve you problem like so:
UserInputService.InputBegan:Connect(function(input)
RS.Heartbeat:Connect(function()
if input.KeyCode == Enum.Keycode.LeftControl then
-- Your code here
end
end)
end)
You would have to remove the whole inputended part and just use a variable. Once the key is pressed, set the variable to the opposite of itself, detailed in my post above, then check if the variable is equal to true, if it is, then make them run, else, make them stop running.
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
local runSpeed = 48 – Run Speed
local function running()
humanoid.WalkSpeed = runSpeed
end
local function stopRunning()
humanoid.WalkSpeed = 16 – Normal Speed
end
game:GetService(“UserInputService”).InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
running = not running
end
end)
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
local runSpeed = 48 – Run Speed
– Function to make the character run
local function running()
humanoid.WalkSpeed = runSpeed
end
local function stopRunning()
humanoid.WalkSpeed = 16 – Normal Speed
end
game:GetService(“UserInputService”).InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
running = not running
if running == true then
running()
else
stopRunning()
end
end
end)