UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Space then
hrp.Anchored = false
addForces(hrp.CFrame.LookVector * 75 + Vector3.new(0, 10, 0), hrp.CFrame)
wait(1)
endForces()
end
end)
How can I check if a player did not press space after 1 second ?
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.Space then
hrp.Anchored = false
addForces(hrp.CFrame.LookVector * 75 + Vector3.new(0, 10, 0), hrp.CFrame)
task.wait(1)
if UIS:IsKeyDown(Enum.KeyCode.Space) then --space is down after 1 second
--do stuff
else --space is not down
--do other stuff
end
endForces()
end
end)
You can call “IsKeyDown()” through the “UserInputService” service and pass to it the enumeration of a key of which you want to check if it is being held down or not.
Not sure if “tick()” alone is really relevant.
I’d recommend adding a debounce to the above function as well.
You could also use “GetKeysDown()” another function from the “UserInputService” which returns an array of enumeration keycodes corresponding to the current keys being held down.