Help With Updating and Setting TextLabels

local mapHolder = game:GetService("ServerStorage").MapHolder
local Children = mapHolder:GetChildren()
local Index = math.random(1,#Children)
local randomInt = Children[Index]

local finalMap = mapHolder:FindFirstChild(randomInt.Name):Clone()   
finalMap.Parent = workspace

game.StarterGui.ScreenGui.DisasterLabel.Text = "The Map Is " .. finalMap.Name

Hey ya’ll! I’m a very new programmer so I followed this tutorial in order to make a random map selector. The code above is part of a script in that tutorial.
The script is in ServerScriptService, MapHolder is a folder of maps in serverStorage and ‘DisasterLabel’ is in starterGUI.
The code that changes the text of DisasterLabel (that i wrote myself, hence the issues) does nothing. I realized that text in a TextLabel can only be changed with a localScript in the label itself, but I have no clue how I’d communicate between the two scripts in order to change the text. Any help?

If anything is unclear, hmu. I may have forgotten details.

Thanks in advance!

You’re going to have to change each player’s PlayerGui.
It’s preferable to change text locally, but I believe it’s fine for this case to change it on the server.

Try this:

--//Services
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

--//Variables
local mapHolder = ServerStorage.MapHolder

--//Controls
local Children = mapHolder:GetChildren()
local Index = Random.new():NextInteger(1, #Children)
local randomInt = Children[Index]

--//Initialization
local finalMap = mapHolder:WaitForChild(randomInt.Name):Clone()   
finalMap.Parent = workspace

for i, player in ipairs(Players:GetPlayers()) do
	task.spawn(function()
		local PlayerGui = player:WaitForChild("PlayerGui", 5)

		if not PlayerGui then
			return
		end

		PlayerGui.ScreenGui.DisasterLabel.Text = "The Map Is ".. finalMap.Name
	end)
end
1 Like