Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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
0
is this a local script or server-sided script? Gmorcad12345 434 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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)
Ad

Answer this question