Player UI not updating?

Making a minigame and there are events in it, and a UI notifies the players the event happening using a UI. Issue is, for the Meteor string, it works whenever it needs to, but the Disco one does not, and it doesn’t switch text.

local eventnames = {
	"A random plate becomes a disco",
	"A random plate is hit by a meteor"
}

local random = math.random(1,2)

for i,p in pairs(game.Players:GetChildren()) do
	for i2,e in pairs(eventnames) do
		if i2 == random then
	      	p.PlayerGui.ScreenGui.UI.Event.Text = e
		end
	end
end

This is part of a larger script but this is a smaller version that displays the issue

Is there any reason why you aren’t just changing the Gui text when random is selected?

It would be more efficient to do this:

local eventnames = {
	"A random plate becomes a disco",
	"A random plate is hit by a meteor"
}

local random = eventnames[math.random(1, #eventnames)] -- select the event randomly

for _, player in pairs(game.Players:GetChildren()) do
	player.PlayerGui.ScreenGui.UI.Event.Text = random
end

Also, it’s a good practice to use remote events for modifying UI instead of doing it from the server.

1 Like

Thing is, in the larger part of the script, there is also another require for random = math.random, but I can try integrating your method into mine, ill respond with results

1 Like

I could have given you a response that achieves what you similar to the method you’re already trying, but I think it would be easier to do that if I had an idea of what the rest of the script is doing.

If it doesn’t work feel free to shoot me a private message.

1 Like

If you would like, I could send the script and try to explain it. Also, after some quick thinking with your method I couldn’t find a way to integrate it into my script, although there may be a way I haven’t thought of.

another thing is that never use GetChildren() for players, that gets any item inside the players service, players or not, use GetPlayers()

1 Like