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

Why isn't my text label updating?

Asked by
CodeWon 181
3 years ago
Edited 3 years ago

My script is supposed to update a text label via a string value, but it doesn't work, why?

This is the main script in my game:

local status = game.ReplicatedStorage:WaitForChild("Status")

status.Value = "2 players are needed to start a game"
print("Not enough players")

repeat wait() until game.Players.NumPlayers >= 2

(This is in a while loop) It changes the status/string value as well but not the text label.

This is the local script inside of the text label:

local status = game.ReplicatedStorage:WaitForChild("Status")

status.Changed:Connect(function()
    script.Parent.Text = status.Value
end)
1
Are you receiving any errors in the output? If so, what are they? COUNTYL1MITS 312 — 3y
0
No, not at all CodeWon 181 — 3y

2 answers

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago
Edited 3 years ago

i think you forgot to change the status in the main script therefore text is not changing as well?

local status = game:GetService("ReplicatedStorage"):WaitForChild("Status")

status.Value = "2 players are needed to start the game"
print("Not enough players")
players = game.Players:GetPlayers()

local playercount = #players -- amount of players
repeat wait() until playercount >= 2

local text = playercount.."players are in game." -- you can change this to whatever you want

status.Value = text 

game.Players.PlayerAdded:Connect(function()
    status.Value = text
end)

game.Players.PlayerRemoving:Connect(function()
    status.Value = text
end)
Ad
Log in to vote
0
Answered by
CodeWon 181
3 years ago

I figured it out myself! I found this in a forgotten old sword fighting game I made, this is a local script inside the text label:

local Status = game:GetService("ReplicatedStorage"):WaitForChild("Status")

script.Parent.Text = Status.Value

Status:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.Text = Status.Value
end)

Answer this question