Menu Gui with camera

I am working in one Camera menu it works. But I want to make one one keybind for back to that menu (ResetOnSpawn is off) It works too but I cant change the camera again. And in Camera menu I destroy on line 24 (turn player camera to normal)

--CameraScript (Inside StarterGui)

local player = game.Players.LocalPlayer
local character = player.CharacterAdded
local Mouse = player:GetMouse()
local camera = game.Workspace.CurrentCamera

local defualtCframe = camera.CFrame
local view = 150
local blur = game.Lighting.Blur

blur.Size = 10

function updateCamera()
	camera.CFrame = game.Workspace.SkyBox.MenuCamera.CFrame
end

game:GetService("RunService").RenderStepped:Connect(updateCamera)

script.Parent.MouseButton1Click:Connect(function()
	wait(0.2)
	blur.Size = 0
	camera.CameraType = Enum.CameraType.Custom
		script.Parent.Parent.Parent.Parent.MenuGui.Enabled = false
		script.Parent.Parent.Parent.Parent.MenuGui.ResetOnSpawn = false
	    script.Parent:Destroy()
end)


--Back to menu script by one keybind (script inside StarterPlayersScripts)

function onKeyPress(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		for _, Player in pairs(game.Players:GetPlayers()) do
			Player.PlayerGui.BackToMenuGUI.TimeGui.TimerLabel.Cooldown.Value = 10
			wait(0.8)
			Player.PlayerGui.BackToMenuGUI.Enabled = true
			wait(10)
			Player.PlayerGui.BackToMenuGUI.Enabled = false
			Player.PlayerGui.MenuGui.ResetOnSpawn = true
			Player.Character.HumanoidRootPart.CFrame = CFrame.new(-5777.103, 1312.392, 372.755)
				end
			end
		end
		
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.F2)
2 Likes

you can literrally destroy this script after the player click play button using script:Destroy()

1 Like

I know but I want to back to that menu again by one keybind the problem is that. And If I destroy that script I cant click play again.

you can make it a connection and disconnect?
something like

local connection = renderstep connection here

connection:Disconnect()

1 Like

maybe I can but I cant just change the camera to normal when I click Play?(I used :Destroy for change it to normal)

Yeah don’t delete the script that’s why it is not working. You need to disconnect the function as @Creeperman16487 said. This way the function can only run once. But youll need to connect it again when the player presses the number.