Can you elaborate what you mean here? I don’t quite understand what your going for.
Are you trying to activate your if statement when the button is clicked while spacebar is held?
Or are you trying to use the spacebar whilst clicking on the button (If this is the case, then its likely something in the script as I know of nothing like that in the engine)
local function Thing()
print("Button or Spacebar Pressed")
end
Button.Activated:Connect(function()
Thing()
end)
game:GetService("UserInputService").InputBegan:Connect(function(Input, Processed)
if Input.KeyCode == Enum.KeyCode.Space and not Processed then
Thing()
end
end)
I admit I’m an amatuer, so somebody probably has a better solution than I do, however,
button.Activated
and
button.MouseButton1Click --- Or 2, depending on what your going for
are both events, and so is the method of getting spacebar from UserInputService.
Whilst there are other ways, I would recommend either:
Having 2 separate activation sources, eg
button.Mouse1Click:Connect(Function()
--- yadda yadda
)
userinputserver.InputBegan:Connect(Function(input)
----- yadda yadda
)
or Having the UserInputService event inside of the Mouse1Button Event.
I forgot to elaborate about those functions being events.
Unfortunately, you cant have events in an if statement, atleast one that leads into a function.
Maybe you can find info on that elsewhere, I havent messed much with stuff like this.
Heres a good example on how to use userinputservice that i took from developer.roblox.com:
local UserInputService = game:GetService("UserInputService")
local function onInputBegan(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
-- your code to open the gui here
end
end
UserInputService.InputBegan:Connect(onInputBegan)