Y_VRN

SHCS_01-15-2022_23-45_isir2204_REVISION-1_TITLE30-Wondering how to use UserInpu

Jan 15th, 2022 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. --[[=================================================
  2.     SH QUESTION: Wondering how to use UserInputService to make "M = Go back to MenuGui" ?
  3.         >   DATE: 1/13/2022
  4.         >   BY USER: isir2204
  5.     SOLUTION VERSION: 1
  6.     REASON WHY THE ANSWER ON SH WASN'T EDITED:
  7.         >   << Visiting scriptinghelpers.org doesn't work (Error 524, connection timeout)
  8. --]]--START YOUR SELECTION ON THE NEXT LINE---------
  9. -- Variables
  10. local player = game.Players.LocalPlayer
  11. local character = player.CharacterAdded
  12. local UIS = game:GetService("UserInputService")
  13. local mouse = player:GetMouse()
  14. local camera = game.Workspace.Camera
  15.  
  16. local defualtCFrame = camera.CFrame
  17. local view = 150
  18. local blur = game.Lighting.Blur
  19.  
  20. local menuMusic = game.Workspace.MenuMusic
  21. local menuFrame = script.Parent.MenuFrame
  22.  
  23. local menuOn = false
  24.  
  25. -- Scripting in Action
  26.  
  27. local connection
  28.  
  29. function updateCamera()
  30.     camera.CFrame = game.Workspace.MenuCamPart.CFrame
  31. end
  32.  
  33. function showMenu() -- Moved most of the code from onInputBegan to here.
  34.     menuOn = true
  35.     wait(0.2)
  36.     blur.Size = 11
  37.     menuMusic:Play()
  38.     camera.CameraType = Enum.CameraType.Scriptable -- You might need this to be set to scriptable so you can change the CFrame property of the camera.
  39.     menuFrame.Visible = true
  40.  
  41.     -- Set camera connection
  42.  
  43.     connection = game:GetService("RunService").RenderStepped:Connect(updateCamera)
  44. end
  45.  
  46. function hideMenu() -- Moved most of the code from "Pressing M" to here.
  47.     menuOn = false
  48.     wait(0.2)
  49.     blur.Size = 0
  50.     menuMusic:Stop()
  51.     camera.CameraType = Enum.CameraType.Custom
  52.     menuFrame.Visible = false
  53.  
  54.     -- Disconnect camera
  55.  
  56.     connection:Disconnect()
  57. end
  58.  
  59. -- When the player joins, (or even resets,) automatically show the menu and play the scenery.
  60.  
  61. showMenu()
  62.  
  63. local function onInputBegan(input : InputObject, gameProcessed)
  64.     if (input.KeyCode == Enum.KeyCode.M) and not menuOn then
  65.         showMenu() -- Executes the function to show menu.
  66.     end
  67. end
  68.  
  69.  
  70.  
  71. script.Parent.MenuFrame.DeployButton.MouseButton1Click:Connect(function()
  72.     hideMenu()
  73. end)
  74.  
  75.  
  76. UIS.InputBegan:Connect(onInputBegan)
Advertisement
Add Comment
Please, Sign In to add comment