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

Help w/ playergui visible?

I need help with getting players and making their gui visible for 2 seconds.

	players = game.Players:GetChildren()
		for i,v in pairs (players) do
			players.PlayerGui.TimeNote.Timer2.Visible = true
			wait(2)
			players.PlayerGui.TimeNote.Timer2.Visible = false

		end

2 answers

Your issue is that you're accessing the player wrong, the script below accesses the player in the correct way.

players = game.Players:GetChildren()
for i,v in pairs (players) do
	-- When doing loops you use the second variable you create as the "child"
	v.PlayerGui.TimeNote.Timer2.Visible = true
	wait(2)
	v.PlayerGui.TimeNote.Timer2.Visible = false
end

Hope this helped!

Sincerely, jmanrock123

1 comment

0

This still won't work as intended. The function for each player needs to be asynchronous, else it won't work properly.

Here's a fixed version of your script:

for _, player in pairs(game.Players:GetChildren()) do
    spawn(function()
        player.PlayerGui.TimeNote.Timer2.Visible = true
        wait(2)
        player.PlayerGui.TimeNote.Timer2.Visible = false
    end)
end

What you were doing wrong is referencing the player incorrectly. You also should use spawn to spawn the function, else this will happen for one player after the next and not at the same time.

What spawn does is run a function, but still continue with the rest of the code without stopping if there's a pause (like using wait).

I hope this helps! Good luck.

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