✓ Accepted answer
Instead of using the ContextActionService use UserInputService and a repeat loop.
#InputBegan
It will run once there is input, if it's a Regular script, it runs when ANY player does any input. If it's a local script then it only runs once a certain
local userinputservice = game:GetService("UserInputService")
userinputservice.InputBegan:connect(function(key, processed)
if key.KeyCode == Enum.KeyCode.Space and not processed then
print("Pressed space")
end
end)
#InputEnded
This runs once you stop inputting.
local userinputservice = game:GetService("UserInputService")
userinputservice.InputEnded:connect(function(key, processed)
if key.KeyCode == Enum.KeyCode.Space and not processed then
print("Stop pressing space")
end
end)
#repeat
This loops until something is true
local a = 0
repeat
a = a+1
wait()
until a > 5
#Final Product
local userinputservice = game:GetService("UserInputService")
local looped = false
userinputservice.InputBegan:connect(function(key,processed)
if key.KeyCode == Enum.KeyCode.Space and not processed then
looped = true
repeat
wait()
until not looped
end
end)
userinputservice.InputEnded:connect(function(key, processed)
if key.KeyCode == Enum.KeyCode.Space and not processed then
looped = false
end
end)
Hope it helps!
2 comments
How does not processed not work? http://wiki.roblox.com/index.php?title=API:Class/UserInputService/InputBegan There is a game processed event.
OH NVM Not processed means that it does not run if you're chatting or typing into a textbox.