Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

GUI problems in Online Mode?

Hello.

Earlier this week, I had made a GUI to pick a class (I've made an entire 'class' system to my game), and I have just started to make it show up under the correct conditions.

In Play Solo, it works as expected, which is- On every respawn, check if the class is one of these... ...or the player is on this team, and if they are, they get shown the GUI.

However, I've tested it in several instances of Online Mode (on a server), and it doesn't seem to be working properly. I have also tested it with the new 1 player server feature on studio, where you can see the output.

It gave me this error: Players.Player1.PlayerGui.RespawnRules:43: bad argument #1 to 'pairs' (table expected, got nil)

... however, I added a wait(0.1) to the script, and a wait(0.05) to the script that handles the Global Functions and Global Variables that were referenced by the script.

That seemed to iron out that error, or at least the output of it.

But the same problem still arises, the GUI never gets cloned under the circumstances that would be enough in Play Solo mode.

Here's the script in case you need it:

wait(0.05)
game.Players:WaitForChild(game.Players.LocalPlayer.Name)
Player = game.Players.LocalPlayer

Player.CharacterAdded:connect(function(Character)
	for a,b in pairs(_G.Monsters) do
		wait()
		if b == Player.Class.Value or Player.TeamColor == BrickColor.new("Earth green") then
			local ms = game.ServerStorage.MonsterSelect:clone()
			ms.Parent = Player.PlayerGui
			break
		end
	end
end)

_G.Monsters is a table properly referenced in another script (server-side). If you want the code snippet, here:

_G.Classes = {"Dwarf","Zombie","Nighthunter","Ogre","Thing","NA","Imp","Golem","Savage"}
_G.Monsters = {"Zombie","Nighthunter","Ogre","Thing","Imp","Golem","Savage"}

Thanks for reading; all replies are appreciated!

2 answers

_G variables defined in a server-side script can not be accessed by a Local Script in online mode. You can use the following solution: Add a RemoteFunction to the workspace. Inside the RemoteFunction, put a server-sided script. Put the following code in that script:

function script.Parent.OnServerInvoke()
	return _G
end

Then, in your Local Script, change the 6th line to this:

for a,b in pairs(workspace.RemoteFunction:InvokeServer().Monsters) do

Try adding the tables into the same script.

It would also probably be better to instead of cloning a GUI in ServerStorage to just make one Visible.

Other than that, I don't know.

This discussion is preserved as it was. New answers, comments, and votes are closed.