I am scripting a receptionist check in and it seems to work fine in studio with a localscript, but when I test in online (or in studio testing) "_G." becomes nil or I get an error "attempt to index a nil value," a variable which has _G. in front of it.
script:
script.Parent.Parent.Submit.MouseButton1Click:connect(function()
for i,v in pairs(game.Players:GetChildren()) do
print("Finding User")
if v.Name == script.Parent.Parent.UsernameInput.Text then
print("Found User "..v.Name)
local CurrentUserServing = v.Name
_G.CurrentUser = v
end
end
print("Next Step")
------------ FOR CHECK IN
if script.Parent.Parent.TableType.Text == "Normal" then
print("Table Type Collected")
if script.Parent.Parent.SeatNumber.Text == "Two" then
print("Table Info Established")
local Card = Instance.new("Tool")
Card.Name = script.Parent.Parent.NumberOfTable.Text.." [] 2 Seater"
Card.RequiresHandle = false
Card.Parent = _G.CurrentUser.Backpack
for i,v in pairs(game.Workspace.ReceptionBoard2.MainBoard.SurfaceGui.BackgroundFrame:GetChildren())do
if script.Parent.Parent.SeatNumber.Text == v.Name then
v.Occupation.Value = true
v.Occupation.Value = false
local NameToHold = Instance.new("StringValue")
NameToHold.Name = "UsernameOwner"
NameToHold.Value = _G.CurrentUser.Name
NameToHold.Parent = v
end
end
end
end
end)
Thanks!

1 comment
I don't think you should be using _G. It's bad practice because it makes you prone to naming conflicts. Maybe consider using a module script? Also, keep in mind that _G is separate for the client and server.