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

My roblox zombie defense game "Wave" gui is not updating. Can someone help?

Im making a roblox zombie defense game but when i update the wave gui value for showing how many waves have passed, the gui does not update.

Can someone help?

local spawns = script.Parent

local spawnTime = 30

local wave = game.StarterGui.ScreenGui.Value.Value


while true do
	game.StarterGui.ScreenGui.TextLabel.Text = 'Wave: '..wave
	wait(spawnTime)
	wave += 1
	for _, spwn in pairs(spawns:GetChildren()) do
		if spwn:IsA('BasePart')then
			local ZombieClone = game.ReplicatedStorage.Zombie:Clone()
			ZombieClone.Parent = workspace
			ZombieClone.HumanoidRootPart.CFrame = CFrame.new(spwn.Position + Vector3.new(0,3,0))
		end
	end
end

1 comment

0

is this a local script or server-sided script?

1 answer

Try this, it fires to all clients. I'll explain. I created a variable with info about the wave, and sent it through the remote event so when the clients all receive it, the data is passed through and will properly update their gui,

Here's the edited server script: Remember to Insert a remote event in replicated storage and name it "UpdateAllClients"

local replicatedStorage = game:GetService("ReplicatedStorage")
--Insert a remote event in replicated storage and name it "UpdateAllClients"
local remoteEvent = replicatedStorage:WaitForChild("UpdateAllClients")

local spawns = script.Parent

local spawnTime = 30

local wave = game.StarterGui.ScreenGui.Value.Value


while true do
	updateClientsGui = 'Wave: '..wave
	remoteEvent:FireAllClients(updateClientsGui)
	wait(spawnTime)
	wave += 1
	for _, spwn in pairs(spawns:GetChildren()) do
		if spwn:IsA('BasePart')then
			local ZombieClone = game.ReplicatedStorage.Zombie:Clone()
			ZombieClone.Parent = workspace
			ZombieClone.HumanoidRootPart.CFrame = CFrame.new(spwn.Position + Vector3.new(0,3,0))
		end
	end
end

Now create a local script in StarterPlayerScripts and paste the following:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("UpdateAllClients")

remoteEvent.OnClientEvent:Connect(function(updateClientsGui)
	local player = game.Players.LocalPlayer
	player.PlayerGui.ScreenGui.TextLabel.Text = updateClientsGui
end)

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