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

My "for i,v in pairs(Game.players:GetPlayers()) do " is doing error with gui ?

So when i try to show a gui like this . in a script in the ServerScriptService

while true do
	wait(10)
	for i,v in pairs(game.Players:GetPlayers()) do
		v.PlayerGui.GUI.Block.Visible = true
	end
end

and after this . it show me this in the output !

17:21:51.288 - GUI is not a valid member of PlayerGui

and by the way the gui is in the playerGui !

2 comments

0

PlayerGui's descendants are not accessible by server scripts, you have to use a local script to access it

0

Just a side note, it seems you're making this an infinite loop, but after it becomes visible you don't exactly need to make it visible again every 10 seconds unless something else is making it invisible repeatedly...

1 answer

✓ Accepted answer

You cannot access PlayerGui from ServerScriptService. Here is what you should do instead:

Create a "RemoteEvent" inside of ReplicatedStorage and name it "blockEvent"

You should have a server script with this code:

while wait(10) do --Every 10 seconds
	game:GetService('ReplicatedStorage'):WaitForChild('blockEvent'):FireAllClients() --Fires everyone's client to set the visiblility to true.
end

You should have a local script inside StarterGui with this code:

game:GetService('ReplicatedStorage'):WaitForChild('blockEvent').OnClientEvent:connect(function() -- When the client is fired from that player.
	script.Parent.GUI.Block.Visible = true --Set the visibility to true.
end)

Hope this helps! If you need further help, just comment.

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