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.
01 | local map = script.Parent.Parent.MinimapFrame |
02 | local button = script.Parent |
03 |
04 | button.MouseButton 1 Click:Connect( function () |
05 | if map.Visible = = true then |
06 | map.Visible = false |
07 | button.Text = "Open Map" |
08 | else |
09 | map.Visible = true |
10 | button.Text = "Close Map" |
11 | end |
12 | end ) |
13 |
14 | local userInputService = game:GetService( "UserInputService" ) |
15 |
01 | local map = script.Parent.Parent:WaitForChild( "MinimapFrame" ) |
02 | local button = script.Parent |
03 |
04 | button.MouseButton 1 Click:Connect( function () |
05 | if map.Visible = = true then |
06 | map.Visible = false |
07 | button.Text = "Open Map" |
08 | else |
09 | map.Visible = true |
10 | button.Text = "Close Map" |
11 | end |
12 | end ) |
13 |
14 | local userInputService = game:GetService( "UserInputService" ) |
15 |
01 | local map = script.Parent.Parent:WaitForChild( "MinimapFrame" ) |
02 | local button = script.Parent |
03 |
04 | button.MouseButton 1 Click:Connect( function () |
05 | if map.Visible = = true then |
06 | map.Visible = false |
07 | button.Text = "Open Map" |
08 | else |
09 | map.Visible = true |
10 | button.Text = "Close Map" |
11 | end |
12 | end ) |
13 |
14 | local mouse = game.Players.LocalPlayer:GetMouse() |
15 |
16 | mouse.KeyDown:Connect( function (input) |
17 | if input = = "M" then |
18 | map.Visible = not map.Visible |
19 | end |
20 | 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:
01 | local map = script.Parent.Parent.MinimapFrame |
02 | local button = script.Parent |
03 |
04 | button.MouseButton 1 Click:Connect( function () |
05 | if map.Visible = = true then |
06 | map.Visible = false |
07 | button.Text = "Open Map" |
08 | else |
09 | map.Visible = true |
10 | button.Text = "Close Map" |
11 | end |
12 | end ) |
13 |
14 | local userInputService = game:GetService( "UserInputService" ) |
15 |