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!
If i'm not mistaken, the client (local scripts) does not have permission to write to _G, only to read from it. You would need a server script to be able to write to it. But as ScrewDeath said, using _G just isn't good practice anymore.