I’ve scripted a command that starts an event within the server. It displays the title, progress and a timer for how long the event has been running. Here’s what it looks like and how it works at the moment:
At the moment, the GUI doesn’t show for players that join after I run the command, only the players who were in the server at that moment, which isn’t ideal.
However, I’d also like it to show for players that join after the command is run, and players currently in the server. Including the timer’s progress, but this isn’t totally necessary.
if verbal == "Training" and trainings == false then
for i,v in pairs(game.Players:GetPlayers()) do
local Training = v.PlayerGui.Trainings.TextLabel
local Status = v.PlayerGui.Trainings.Line2
local Timer = v.PlayerGui.Trainings.Line
local HostName = Character.Name
local TimerScript= game.StarterGui.Trainings.Line.LocalScript
TimerScript.Disabled = false
Status.Text = "Awaiting participants.."
Event.Text = "TRAININGS"
Timer.LocalScript.Disabled = false
trainings = true
end
end
Here’s the server side which delivers the GUI to the players in the server - sorry in advance for my messy scripting.
Any ideas how I can achieve this, if it is possible?
So long as you’re trying to learn, we don’t care what your experience is.
Take the code that adds the GUI and make it a function like this:
local function add_gui(plr)
local Training = plr.PlayerGui.Trainings.TextLabel
local Status = plr.PlayerGui.Trainings.Line2
local Timer = plr.PlayerGui.Trainings.Line
local HostName = plr.Character.Name
-- lines below this might have a problem, but we can deal with that in a second
local TimerScript= game.StarterGui.Trainings.Line.LocalScript
TimerScript.Disabled = false
Status.Text = "Awaiting participants.."
Event.Text = "TRAININGS"
Timer.LocalScript.Disabled = false
trainings = true
end
This allows the code to be re-used in multiple places.
Then adapt the for loop to use the function.
for i,v in pairs(game.Players:GetPlayers()) do
add_gui(v)
end
Then connect the PlayerAdded event to use the same function.