local input = {}
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local returnInput = function()
mouse.Button1Down:Connect(function()
return true
end)
end
input.checkInput = function()
return returnInput()
end
return input
local script:
local inputModule = require(script.Input)
local inp_Bool = inputModule.checkInput()
print(inp_Bool )
It returns nil every time I print the bool.Am I missing something?
You couldn’t do it this way, because that value would be returned internally to where the event listener was called from, which doesn’t handle returned values at all.
If you’re trying to yield until a button is pressed, you could do:
If you’re trying to return if the player has their mouse down, in your local ReturnInput function, just do this
local returnInput = function()
return game:GetService("UserInputService"):IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
end
Or scrap the returnInput and just put it with checkInput instead since it would be a bit unneeded to use that function in this case
Or if you’re wanting to wait until the player’s mouse is down, do what @C_Sharper mentioned
Edit: Usually just for organization sakes, I would recommend putting game:GetService("UserInputService") in a variable if you plan to use it more than once, since it has events and functions for handling input
That’s the same thing C_Sharper mentioned about yielding/waiting till the mouse is down, also :Wait() is preferred over :wait() since the latter is deprecated