I have a code where it gets a stringvalue and intvalue located in replicatedstorage and updates it based on events, this being about a countdown function. I also have textlabels in a screengui that updates the code based on if the values are changed.
The timer textlabel seems to be fine updating every second, but for some reason the event textlabel doesn’t work until later on in the code where the stringvalue updates a second time and that’s when the event textlabel starts working.
I’ve tried putting the stringvalue in the actual code that runs when the countdown is about to start, which it didn’t update either. I’ve also proofread the variables to see if anything has been misspelt or mistakenly capitalised.
ModuleScript:
local module = {}
-- services
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local soundService = game:GetService("SoundService")
-- variables
local sfx = soundService.SoundEffects
local bass = sfx.bass
local gameData = replicatedStorage:WaitForChild("GameData")
local timer = gameData.Timer
local status = gameData.Status
-- sets timer to 30, then decreases timer every second then round begins once timer hits 0
function module.Countdown()
timer.Value = 5
status.Value = "Round starts in..."
print(status.Value)
repeat
timer.Value -= 1
bass:Play()
wait(1)
until timer.Value == 1 --
status.Value = "Round starting!"
wait(5)
gameData.RoundInProgress.Value = true
end
return module
LocalScript (the one located inside the event textlabel)
-- services
local replicatedStorage = game:GetService("ReplicatedStorage")
-- variables
local gameData = replicatedStorage.GameData
local eventLabel = script.Parent
gameData.Status:GetPropertyChangedSignal("Value"):Connect(function()
eventLabel.Text = gameData.Status.Value
end)
EDIT: Here’s the serverscript too
-- services
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local serverStorage = game:GetService("ServerStorage")
local serverScriptService = game:GetService("ServerScriptService")
-- variables
local module = require(serverScriptService.Modules.CountDown)
local platesFolder = workspace.PlatesFolder
local gameData = replicatedStorage.GameData
local plates = serverStorage.Plates
-- clones all plates in the plates folder located in serverstorage
function ClonePlates()
for _, plate in pairs(plates:GetChildren()) do
local newPlate = plate:Clone()
newPlate.Parent = platesFolder
end
end
-- gives each player a unique plate, then deletes all the unused ones
function AssignPlates()
local usedPlates = {}
for _, plr in pairs(players:GetPlayers()) do
local character = plr.Character
local randomPlate
repeat
randomPlate = plates:GetChildren()[math.random(1, #plates:GetChildren())]
until not usedPlates[randomPlate]
usedPlates[randomPlate] = true
local root = character:WaitForChild("HumanoidRootPart")
root.CFrame = randomPlate.CFrame + Vector3.new(0, 3, 0)
end
print(usedPlates)
for _, plate in pairs(plates:GetChildren()) do
if not usedPlates[plate] then
plate:Destroy()
end
end
end
players.PlayerAdded:Connect(function()
if gameData.RoundInProgress.Value == false then
if #players:GetPlayers() >= 1 then
module.Countdown()
else
gameData.Status.Value = "Waiting for more people..."
end
repeat wait() until gameData.RoundInProgress.Value == true
ClonePlates()
AssignPlates()
end
end)