I’m trying to make a plane script that keeps firing a RemoteEvent that makes the plane go up until E is done being pressed. That works great, but it doesn’t make the Enum.UserInputState.End fire, it just prints Enum.UserInputState.Begin, even when I push other buttons.
Here’s my LocalScript:
local service = game:GetService("ContextActionService")
local function handleAction(actionName, inputState, inputObject)
if actionName == "FlyUp" then
if inputState == Enum.UserInputState.Begin then
repeat
print("ooh!")
print(inputState)
game.ReplicatedStorage.FlyUp:FireServer()
wait(0.1)
until inputState == Enum.UserInputState.End
end
end
-- some unimportant keybind stuff
inputstate won’t change, rather it will fire handleAction again with a new inputState variable. You need to move the loop to be contained in an asynchronous external function, and end the loop when you change a variable.
running = false
function run()
spawn(function() while running do
blah
end)
end
function handleActuion(blah)
if inputState blah then
running = true
run()
else
running = false
end
end
local service = game:GetService("ContextActionService")
local inputEnded = false
local function handleAction(actionName, inputState, inputObject)
if actionName == "FlyUp" then
if inputState == Enum.UserInputState.Begin then
repeat
print("ooh!")
print(inputState)
game.ReplicatedStorage.FlyUp:FireServer()
wait(0.1)
until inputEnded == true
inputEnded = false
elseif inputState == Enum.UserInputState.End then
inputEnded = true
end
end
-- some unimportant keybind stuff