How do I call a service / location in a function that was called in another function?

Well today I decided to do something difficult:
Hi users, this time I’m doing a modolue script related to Debugging, I’ll show you the part I have doubts:

local ModuleLocationsDebug = {}

local function GetLocation()
–Services
local Workspace = game:GetService(“Workspace”)
local Players = game:GetService(“Players”)
local CoreGui = game:GetService(“CoreGui”)
local Lighting = game:GetService(“Lighting”)
local MarketplaceService = game:GetService(“MarketplaceService”)
local ReplicatedFirst = game:GetService(“ReplicatedFirst”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local ServerScriptService = game:GetService(“ServerScriptService”)
local ServerStorage = game:GetService(“ServerStorage”)
local StarterGui = game:GetService(“StarterGui”)
local StarterPack = game:GetService(“StarterPack”)
local SoundService = game:GetService(“SoundService”)
local Chat = game:GetService(“Chat”)
local LocalizationService = game:GetService(“LocalizationService”)
local TestService = game:GetService(“TestService”)
–Locations
local LocalPlayer = Players.LocalPlayer
local CharacterPlayer = LocalPlayer.Character
local GuiDebug = script.Parent.Parent.GuiDebug
local DebugInitial = script.Parent.DebugInitial
end

local function levels()
local Testers = {“funtimeandrefoxy”,“Player1”,“Player2”}

--how do I put Players here?

--local PP = GetLocation(Players.PlayerAdded)

end

return ModuleLocationsDebug

As seen I have 2 functions (one related to locations and one related to functions), but I would like to know if there was any way to invoke the Service Players that is located in the GetLocation () function within levels () [this is just a placeholder name]. Is it possible to do that?

Not with local variables declared inside of another function. You should probably define all of the variables outside of the GetLocation function, and simply update the variables that could have possibly changed.

The services are pointless to get inside of the function as they won’t change, so I’d move all the definition for those outside the function and don’t redefine them. Things like the Character might change so it’s okay to update those inside the function.

Also use three backticks ``` at the start and end of your code to format it properly as it is incredibly difficult to read right now.

1 Like

OK thanks for helping. I understand.