HI,
I am having lot of trouble trying to figure out how to make this variable called temp will change to true/false when the player presses and holds down Space and presses W twice.
here is the script -
local temp = false
local uis = game.GetService("UserInputService")
uis.InputBegan:Connect(function(key,chat)
if chat then return end
if KeyCode == Enum.KeyCode.SPACE + [2x tap] W then
if temp then
temp = false
print("Changed to False")
else
temp = true
print ("Changed to True")
end
end
end)
hope this is the script you shall need for this…
You have some serious issues with your code. I’ve written something that works here:
local UserInputService = game:GetService("UserInputService")
local spaceIsHeld = false -- check if space is currently held
local temp = false
local Time = tick()
local debounce = false
local COOLDOWN = 0.3 -- Timer for cooldown between double-taps
UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Space then
spaceIsHeld = true -- Space is currently being held.
elseif Input.KeyCode == Enum.KeyCode.W and spaceIsHeld then
-- tick() - Time is checking to see if W has been pressed twice within the timeframe of 0.3 seconds or less,
-- since we recorded the time it was last released in InputEnded.
if tick() - Time < 0.3 and spaceIsHeld and not debounce then
if temp then
temp = false
print("Changed to False")
else
temp = true
print ("Changed to True")
end
-- Needs a debounce or else player can just keep spamming W, and it's not really a double tap.
debounce = true
wait(COOLDOWN)
debounce = false
end
end
end)
UserInputService.InputEnded:Connect(function(Input, GameProcessedEvent)
if Input.KeyCode == Enum.KeyCode.Space then
spaceIsHeld = false -- Space is no longer being held.
elseif Input.KeyCode == Enum.KeyCode.W then
Time = tick() -- After W is released, a time is recorded. This recorded time is check against a new time in InputBegan.
end
end)
It does run but I guess there is no way to make it SPACE + W as is said by @Hypgnosis There needs to be a function where we know when space is help down