Local function errors

Hello, I have been scripting this PauseMenu game system. It’s very simple, Nothing complex. But for some reason it does not work. the output does not give me any errors. Even though all of filters are opened in the output. Do you see an error here?

--Variables
--Gets UI
local StarterGUI = game.StarterGui
local BetaTesterUI = StarterGUI.BetaTesterUI
local AdminPanelUI = StarterGUI["AdminPanelUI(Delayed)"]
local CompassUI = StarterGUI.CompassGui
local GameGUI = StarterGUI.GameGUI
local RadarUI = StarterGUI.RadarGui
local Player = game.Players.LocalPlayer
local player = game.Players
local PlayerService = game:GetService("Players")
local Lightning = game.Lighting
local UIS = game:GetService("UserInputService") --InputService <


-------------------------------------------
--PauseMenu
local PauseMenu = StarterGUI.PauseMenu
local BG = script.Parent.PauseMenuBG
local PauseFrame = script.Parent.PauseMenuBG
local LeaveButton = PauseMenu.PauseMenuBG.PauseFrame.LeaveGame
local ReturnToGameButton = PauseMenu.PauseMenuBG.PauseFrame.ReturnToGame

--Tabs
local SettingButtonTab = PauseMenu.PauseMenuBG.Tabs.TabFrame.Settings
local RankButtonTab = PauseMenu.PauseMenuBG.Tabs.TabFrame.Ranks
local PauseButtonTab = PauseMenu.PauseMenuBG.Tabs.TabFrame.Pause

--LeaveGame Confirmation
local LeaveGameConfirmationFrame = PauseMenu.PauseMenuBG.PauseFrame.LeaveGame.Confirmation
local BackToMainMenuButton = LeaveGameConfirmationFrame.BackToMainMenu
local LeaveGameButton = LeaveGameConfirmationFrame.LeaveGameButton

local function LeaveGame()
      LeaveGameButton.MouseButton1Click:Connect(function()
            LeaveGameConfirmationFrame.Visible = true
            LeaveGame()
            
      end)
end

local function ReturnToGame()
      ReturnToGameButton.MouseButton1Click:Connect(function()
            PauseFrame.Visible = false
            
            if LeaveGameConfirmationFrame.Visible == true then
                  LeaveGameConfirmationFrame.Visible = false
                  
                  --Animation
                  ReturnToGameButton.MouseEnter:Connect(function()
                        local ReturnUIStroke = ReturnToGameButton.UIStroke
                        ReturnUIStroke.Enabled = true
                        
                        ReturnToGameButton.MouseLeave:Connect(function()
                              local LeaveReturnUIStroke = ReturnToGameButton.UIStroke
                              LeaveReturnUIStroke.Enabled = false
                              ReturnToGame()

                        end)
                  end)
            end
      end)
end

local function PauseMenuLeaveGame()
      LeaveButton.MouseButton1Click:Connect(function()
            LeaveGameConfirmationFrame.Visible = true
            PauseFrame.Visible = false
            
            --Animation
            LeaveButton.MouseEnter:Connect(function()
                  LeaveButton.UIStroke.Enabled = true
                  
                  LeaveButton.MouseLeave:Connect(function()
                        LeaveButton.UIStroke.Enabled = false
                      PauseMenuLeaveGame()
                  end)
            end)
      end)
end

--UIS.InputBegan:Connect(function(input,gameProccessedEvent)
      --if input.KeyCode == Enum.KeyCode.Tab then
        --    local Blur = Instance.new("BlurEffect", Lightning)
          --  Blur.Size = 10
      --end
--end)

--Connections
1 Like

You haven’t called the function anywhere…
Also, you have a recursive loop in all of your functions, where you call the function inside the definition of the function… Is this intentional? Perhaps this is why your functions aren’t running…

Can you show us the connections please?

I did call the functions, You can see it under every function.

There is nothing yet under connections.

Yes but you’ve called them inside the functions themselves though, and I’m not sure if that’s what you want. Sometimes this is needed, I’m not sure if this is the case here though.

1 Like

So, If I called them outside the functions it will fix it?

1 Like

Theoretically, yes it should. Let me know how that goes.

1 Like

Yes, connect them to the events and it should work

yes, i forgot to say, you have to connect them to events and call them. Don’t just call them outside of the script, otherwise they’ll run at the start.

It’s still not working.

New Code:

`--Variables
--Gets UI
local StarterGUI = game.StarterGui
local BetaTesterUI = StarterGUI.BetaTesterUI
local AdminPanelUI = StarterGUI["AdminPanelUI(Delayed)"]
local CompassUI = StarterGUI.CompassGui
local GameGUI = StarterGUI.GameGUI
local RadarUI = StarterGUI.RadarGui
local Player = game.Players.LocalPlayer
local player = game.Players
local PlayerService = game:GetService("Players")
local Lightning = game.Lighting
local UIS = game:GetService("UserInputService") --InputService <


-------------------------------------------
--PauseMenu
local PauseMenu = StarterGUI.PauseMenu
local BG = script.Parent.PauseMenuBG
local PauseFrame = script.Parent.PauseMenuBG
local LeaveButton = PauseMenu.PauseMenuBG.PauseFrame.LeaveGame
local ReturnToGameButton = PauseMenu.PauseMenuBG.PauseFrame.ReturnToGame

--Tabs
local SettingButtonTab = PauseMenu.PauseMenuBG.Tabs.TabFrame.Settings
local RankButtonTab = PauseMenu.PauseMenuBG.Tabs.TabFrame.Ranks
local PauseButtonTab = PauseMenu.PauseMenuBG.Tabs.TabFrame.Pause

--LeaveGame Confirmation
local LeaveGameConfirmationFrame = PauseMenu.PauseMenuBG.PauseFrame.LeaveGame.Confirmation
local BackToMainMenuButton = LeaveGameConfirmationFrame.BackToMainMenu
local LeaveGameButton = LeaveGameConfirmationFrame.LeaveGameButton

local function LeaveGame()
      LeaveGameButton.MouseButton1Click:Connect(function()
            LeaveGameConfirmationFrame.Visible = true
            
      end)
end

local function ReturnToGame()
      ReturnToGameButton.MouseButton1Click:Connect(function()
            PauseFrame.Visible = false
            
            if LeaveGameConfirmationFrame.Visible == true then
                  LeaveGameConfirmationFrame.Visible = false
                  
                  --Animation
                  ReturnToGameButton.MouseEnter:Connect(function()
                        local ReturnUIStroke = ReturnToGameButton.UIStroke
                        ReturnUIStroke.Enabled = true
                        
                        ReturnToGameButton.MouseLeave:Connect(function()
                              local LeaveReturnUIStroke = ReturnToGameButton.UIStroke
                              LeaveReturnUIStroke.Enabled = false

                        end)
                  end)
            end
      end)
end

local function PauseMenuLeaveGame()
      LeaveButton.MouseButton1Click:Connect(function()
            LeaveGameConfirmationFrame.Visible = true
            PauseFrame.Visible = false
            
            --Animation
            LeaveButton.MouseEnter:Connect(function()
                  LeaveButton.UIStroke.Enabled = true
                  
                  LeaveButton.MouseLeave:Connect(function()
                        LeaveButton.UIStroke.Enabled = false
                  end)
            end)
      end)
end

PauseMenuLeaveGame()
ReturnToGame()
LeaveGame()


--UIS.InputBegan:Connect(function(input,gameProccessedEvent)
      --if input.KeyCode == Enum.KeyCode.Tab then
        --    local Blur = Instance.new("BlurEffect", Lightning)
          --  Blur.Size = 10
      --end
--end)

It’s meant to be 3 backticks each, also, I can see the issue

PauseMenuLeaveGame()
ReturnToGame()
LeaveGame()

You are calling all of these, but they are all not connected to an event. You may wish to connect it to an event like an UIS key press.

You have to connect the functions to their events, not call them at the beggining so that the functions execute when the event happens.

1 Like

Ok, so basically I will create Remote Events in Replicated Storage and call them right?

In your code, you may want to do it as

UIS.InputBegan:Connect(function(input,gameProccessedEvent)
      if input.KeyCode == Enum.KeyCode.Tab then
           local Blur = Instance.new("BlurEffect", Lightning)
           Blur.Size = 10
           PauseMenuLeaveGame()
      end
end)
1 Like

I also noticed that you connect some code inside the function

No, This part of the code works. I will not use it right now.

Well, that’s one type of event. You can connect them to other events such as UIS.InputBegan, or PlayerAdded.

Please specify when you want to call your functions so that we can help you. When exactly do you want these functions to run?

I have fixed that in the New Code. Which i sent.