For Each Player Gui Change

  1. What do you want to achieve?
    When I run this command it changes a GUI value for everyone in the game.

  2. What is the issue?
    I am getting an error with the following:

				for i, child in ipairs(children) do
					children[i].PlayerGui.StaffServerIndicator.Frame.StaffLock.Text = "StaffLock Off"
  1. What solutions have you tried so far?
    I have tried messing around with the script but have no clue what is wrong with it.

The current Script:

local hrRankID = 160
local groupID = 5209780
local staffLockOn = true
local children = workspace:GetChildren()

	if staffLockOn == true and plr:GetRankInGroup(groupID) < staffRankID then
		plr:Kick("Staff lock is on, the CEO Or Chairman needs to unlock the game.")
	plr.Chatted:Connect (function(msg)
		if plr:GetRankInGroup(groupID) >= hrRankID then
			if msg == ":stafflock on" then
				staffLockOn = true
			if msg == ":stafflock off" then
				staffLockOn = false
				print("Step 1")
				for i, child in ipairs(children) do
					children[i].PlayerGui.StaffServerIndicator.Frame.StaffLock.Text = "StaffLock Off"
1 Like

Didn’t your topic just get locked by contributors?

Yes, becuase the format was incorrect.

1 Like

Fixed it, Used an int value as the placeholder.

You are going through the children of workspace, instead of the children of players.

Also a quick tip: Children[i] in your for loop is the same as child.

Change your code to resemble something like this:

for i, child in pairs(game.Players:GetPlayers()) do
    child.PlayerGui.StaffServerIndicator.Frame.StaffLock.Text = “StaffLock Off”
1 Like

Additionally, when creating scripting support threads relating to an error you should also post the error message you’re getting. Without access to the error message it’s very hard for people to actually find out what’s wrong without trying to recreate your code (which is really time consuming and sometimes impossible if you don’t give enough info). That is after all what errors are for.