longtime lurker here, first post!
Im Working on a wave defense game and would like to have the gui keep players updated as to whats going on. My attempt works for the first cycle and then stays displaying the last update.
My question is how can I approach the gui updates to be continuous during gameplay?
I have 3 remote events in replicated storage [StartMob, Survive, EndMob]
in serverscriptservice, I have a simple while loop for the game enemy spawner in the game manager
all times are short for testing
local creator = require(game.ReplicatedStorage.Creator)
local MOB = game.ServerStorage.Enemy
while true do
wait(10)
creator.make("Enemy")
end
for the module, the routine [sound, visual cue, spawn enemy, clear all enemies] works correctly
local Creator = {} -- Create our module
function Creator.make(part)
local startmob = game.ReplicatedStorage.StartMob
local endmob = game.ReplicatedStorage.EndMob
local survive = game.ReplicatedStorage.Survive
-- fire the remote event to update players gui to prepare
startmob.OnServerEvent:connect(function(player)
startmob:FireClient(player, "The Next Wave Is Coming")
end)
--create sound in sound service--
local sound = game.ServerStorage:FindFirstChild("siren")
local snd = game.ServerStorage:FindFirstChild(sound)
local sndcopy = sound:Clone()
sndcopy.Parent = game.SoundService
wait(10)
sndcopy:Destroy() --destroy sound
-- just for show effect
local beam = game.Workspace.Beam
beam.Transparency = 0
--fire remote for wave start
survive.OnServerEvent:connect(function(player)
survive:FireClient(player, "They're Here!")
end)
--create a clone from storage
local origin = game.ServerStorage:FindFirstChild(part)
local copy = origin:Clone()
copy.Parent = game.Workspace
--time for the clone to do its thing
wait(5)
--remove the effect
beam.Transparency = 1
copy:Destroy() --destroy the clone
--fire remote for end of wave
endmob.OnServerEvent:connect(function(player)
endmob:FireClient(player, "We're Safe...For Now")
end)
end
return Creator
in a local script in the gui: (i have gui in startergui)
local gui = script.Parent.Frame.TextLabel
local survive = game.ReplicatedStorage.Survive
local endmob = game.ReplicatedStorage.EndMob
local startmob = game.ReplicatedStorage.StartMob
startmob.OnClientEvent:connect(function(text)
gui.Text = text
end)
startmob:FireServer()
survive.OnClientEvent:connect(function(text)
gui.Text = text
end)
survive:FireServer()
endmob.OnClientEvent:connect(function(text)
gui.Text = text
end)
endmob:FireServer()
my result is the three updates to the gui occur. im left with were safe for now even when the next wave is ready.
any help would be appreciated!
i checked in the dev articles and educational resources from the roblox pages but either im just stuck or just overthinking this.

1 comment
You should keep your event connections outside of the while loop unless you disconnect them afterwards, this will cause memory leak/lag later on.