I am trying to use UserInputService and it wasn’t working. So, I tried to make a simple script with it for testing and it doesn’t work. Is there something wrong with it? Am I using it wrong?
Script
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
print("W")
elseif input.KeyCode == Enum.KeyCode.A then
print("A")
elseif input.KeyCode == Enum.KeyCode.S then
print("S")
elseif input.KeyCode == Enum.KeyCode.D then
print("D")
end
end)
Yes, you just have to replace the “print()” with “script.Parent[“yourguiname”].Frame.Visible = true/false”
Just add a Frame inside your GUI.
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W then
script.Parent.Gui.Frame.Visible = true
elseif input.KeyCode == Enum.KeyCode.A then
script.Parent.Gui.Frame.Visible = false
elseif input.KeyCode == Enum.KeyCode.S then
print("S")
elseif input.KeyCode == Enum.KeyCode.D then
print("D")
end
end)