I am new to Roblox scripting, and I want to temporarily stop a script from running when I press a key.
Code:
uif = game:GetService("UserInputService")
uif.InputBegan:connect(function(imput)
if imput.KeyCode == Enum.KeyCode.LeftShift then
local plr = game.Players.LocalPlayer
local char = script.Parent.Humanoid
char.WalkSpeed = 21
end
end)
uif.InputEnded:connect(function(imput)
if imput.KeyCode == Enum.KeyCode.LeftShift then
local plr = game.Players.LocalPlayer
local char = script.Parent.Humanoid
char.WalkSpeed = 16
end
end)
This script works as a shift run code, and I want to stop this code from running when I press the key, 'c'.
I tried this way from stopping it:
uif.InputEnded:connect(function(imput)
if imput.KeyCode == Enum.KeyCode.C then
Script.Disabled = true
end
end)
However, the problem is that when I don't press c, the script doesn't work and it stops functioning completely. I tried to put a 'Script.Disabled = false' at the beginning of script, but that doesn't work as well.
Can someone please tell me how I fix this problem so that when I press c, the shift run script doesn't function.
Thank you, this issue has been bugging me for quite a while.

1 comment
Why don't you just make a variable called disabled and set it to true when you press c (or false if its already true). Then you just need to check to make sure that the variable is false before you let the script do anything.