How activate Gui when Pressed button M on keyboard

I already created a map system wich is working perfect, but it aways displaying on screen and i dont want that…

I want the map to only appear when I press the Letter M on the keyboard

So, here is my code on StarterGui

-- Variables
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local MapFolder = game.Workspace:FindFirstChild("MapFolder")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Frame = script.Parent.MapFrame
local PlayerArrow = Frame.PlayerArrow


local Camera = Instance.new("Camera", game.Workspace)
Camera.CameraType = Enum.CameraType.Scriptable
Frame.CurrentCamera = Camera
Camera.FieldOfView = 4


for i, Objects in pairs(MapFolder:GetChildren()) do
	local Clone = Objects:Clone()
	Clone.Parent = Frame
end

RunService.RenderStepped:Connect(function()
	Camera.CFrame = CFrame.new(HumanoidRootPart.Position  + Vector3.new(0,3000,0), HumanoidRootPart.Position)
	PlayerArrow.Rotation = -HumanoidRootPart.Orientation.Y - 90
end)

UserInputService.InputBegan:connect(function(key, chat)
	if key.KeyCode == Enum.KeyCode.M and not chat then
		--> Make your Gui visible
	end
end)

UserInputService.InputEnded:connect(function(key, chat)
	if key.KeyCode == Enum.KeyCode.M and not chat then
		--> Make your Gui invisible
	end
end)
1 Like

It works perfect, thank you, i was trying to do this but the wrong way lol, thx!!!

Oh, it’s alright, glad it helped! :+1:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.