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

Gui shows up for one player at a time instead of all players at the SAME time? [Solved]

I have a script that would show each player a message after a certain time. After the message appears, some code is run. The more players i have in game, the longer it takes. I tested on studio to see what happens with 2 players and i saw that the Gui shows up for one player at a time. I want it to show for all players at the SAME time. Anyone know what i need to do to fix this?

function Message()
	for i,v in pairs(game.Players:GetPlayers()) do
		local msg = v:WaitForChild("PlayerGui").ScreenGui.Message
		message.Visible = true
		wait(3)
		message.Visible = false
	end
end

while true do
	wait(20)
	Message()
	--Code to run
end

Also, this is a normal ServerScript in Workspace.

Any help would be appreciated!

1 answer

✓ Accepted answer

It's because of the wait in the loop inside the function.

I recommend simply using spawn inside the message function, like so:

function Message()
	for i,v in pairs(game.Players:GetPlayers()) do
		spawn(function()
			--I changed this part to msg instead of message. You might not want this.
			local msg = v:WaitForChild("PlayerGui").ScreenGui.Message
			msg.Visible = true
			wait(3)
			msg.Visible = false
		end)
	end
end

while true do
    wait(20)
    Message()
    --Code to run
end

EDIT:

Scripts running on the server can't access GUIs from the players' playerGui that they did not create and add there, meaning it won't see the ScreenGui, or the Message.

You'll have to use Remote Events.

--// Regular Script

local remoteEvent = game.ReplicatedStorage.REMOTEEVENTNAME

while true do
    wait(20)
    remoteEvent:FireAllClients()
end

--// Local Script on the client; like in PlayerGui.

local remoteEvent = game.ReplicatedStorage.REMOTEEVENTNAME
local gui = DEFINE GUI

remoteEvent.OnClientEvent:Connect(function()
	gui.Visible = true
	wait(3)
	gui.Visible = false
end)

11 comments

0

This doesn't seem to be working for me. When i test with 2 players on studio, nothing happens. When i test in game with 2 players, I get an error saying ScreenGui is not a valid member of PlayerGui. I tried changing it to :WaitForChild("ScreenGui") but it gives me infinite yield possible.

0

Yup. Let me edit this.

0

How exactly do i use the RemoteEvent to access the players Gui? I haven't used this before so i'm not so familiar with it.

0

You just put a RemoteEvents in replicated storage and follow the tutorial. There are many tutorials out there to help you understand remote events, but basically they're like a portal, or connection, that lets the Server interact directly with the Client.

0

All you said was to put the remoteEvent inside of replicated storage and then use :FireAllClients() but it doesn't look like it's interacting with the Gui's?

0

FireAllClients() sends a signal to all the clients, signals which the LocalScripts inside the clients can pick up on, and then they can do whatever they want with the information the signal gives.

0

So you need both a Regular Script and a Local Script for this process to work.

0

Okay so i just found out that FilteringEnabled was ENABLED. I disabled it and now the script works without the remoteEvents thing you said.

0

If you're still confused, I recommend watching this: https://www.youtube.com/watch?v=4Dc_bri9mjs

0

Okay, thank you.

0

Well, without Filtering, you're game won't show for people under 13, and the game is super vulnerable to exploits.

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