This is a local script that is in parent with with a frame and now I wanted to add a keyinput that if I press M then it closes or opens the GUI, but it doesnt work. The mouse button click works fine but the key input doesn't.
local map = script.Parent.Parent.MinimapFrame local button = script.Parent button.MouseButton1Click:Connect(function() if map.Visible == true then map.Visible = false button.Text = "Open Map" else map.Visible = true button.Text = "Close Map" end end) local userInputService = game:GetService("UserInputService") userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.M then if map.Visible = true then then map.Visible = false else if map.Visible = false then map.Visible = true end end end end end)
local map = script.Parent.Parent:WaitForChild("MinimapFrame") local button = script.Parent button.MouseButton1Click:Connect(function() if map.Visible == true then map.Visible = false button.Text = "Open Map" else map.Visible = true button.Text = "Close Map" end end) local userInputService = game:GetService("UserInputService") userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if not gameProcessedEvent then if input.UserInputType == Enum.UserInputType.KeyBoard then if input.KeyCode == Enum.KeyCode.M then map.Visible = not map.Visible end end end end)
local map = script.Parent.Parent:WaitForChild("MinimapFrame") local button = script.Parent button.MouseButton1Click:Connect(function() if map.Visible == true then map.Visible = false button.Text = "Open Map" else map.Visible = true button.Text = "Close Map" end end) local mouse = game.Players.LocalPlayer:GetMouse() mouse.KeyDown:Connect(function(input) if input == "M" then map.Visible = not map.Visible end end)
First of all, in your if/then statements you need == instead of just =.
Second, at line 22 you have an extra then.
Fixed code would look like this:
local map = script.Parent.Parent.MinimapFrame local button = script.Parent button.MouseButton1Click:Connect(function() if map.Visible == true then map.Visible = false button.Text = "Open Map" else map.Visible = true button.Text = "Close Map" end end) local userInputService = game:GetService("UserInputService") userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.M then if map.Visible == true then map.Visible = false else if map.Visible == false then map.Visible = true end end end end end)