Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to fix GUI input keycode changes its visiblility?

Asked by
TechModel 118
3 years ago

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.

01local map = script.Parent.Parent.MinimapFrame
02local button = script.Parent
03 
04button.MouseButton1Click: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
12end)
13 
14local userInputService = game:GetService("UserInputService")
15 
View all 29 lines...

2 answers

Log in to vote
1
Answered by 3 years ago

try this

01local map = script.Parent.Parent:WaitForChild("MinimapFrame")
02local button = script.Parent
03 
04button.MouseButton1Click: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
12end)
13 
14local userInputService = game:GetService("UserInputService")
15 
View all 24 lines...

if that doesn't work try this

01local map = script.Parent.Parent:WaitForChild("MinimapFrame")
02local button = script.Parent
03 
04button.MouseButton1Click: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
12end)
13 
14local mouse = game.Players.LocalPlayer:GetMouse()
15 
16mouse.KeyDown:Connect(function(input)
17    if input == "M" then
18        map.Visible = not map.Visible
19    end
20end)

if that doesn't work too then dm me on discord (??#8344) (copy paste the invisible block because I have invisible name very sorry)

0
Thanks for accepting my answer! WINDOWS10XPRO 438 — 3y
0
No worries, glad that you could help me. TechModel 118 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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:

01local map = script.Parent.Parent.MinimapFrame
02local button = script.Parent
03 
04button.MouseButton1Click:Connect(function()
05if map.Visible == true then
06   map.Visible = false
07   button.Text = "Open Map"
08else
09   map.Visible = true
10   button.Text = "Close Map"
11end
12end)
13 
14local userInputService = game:GetService("UserInputService")
15 
View all 29 lines...

Answer this question