I was messing with UserInputService as a test, and when I tried to declare a variable which is equal to a TextButton, it doesn’t work.
This code does work, it has no variables equal to a Gui, it just says it in the if statement:
local userInputService = game:GetService("UserInputService")
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Q then
script.Parent.ScreenGui.TextButton.Visible=true
print("You pressed Q")
wait(1)
script.Parent.ScreenGui.TextButton.Visible=false
print(gameProcessedEvent)
end
end
end)
This is why I’m posting, this will not work:
local userInputService = game:GetService("UserInputService")
local buttonVisibility = script.Parent.ScreenGui.TextButton.Visible
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Q then
buttonVisibility=true
print("You pressed Q")
wait(1)
buttonVisibility=false
print(gameProcessedEvent)
end
end
end)
Why is it that when I declare a variable, nothing works (Not even the print statement worked), but when I just say it, with no variables, it works prints what I want it to print, and makes the Gui visible, then one second laters its invisible again, just how I want it!