The problem here is that you incorrectly assume that the text variable refers to the actual property of the TextLabel. If the Text changes, your variables will not change along with it. They'll stay the same. Take this for example:
local int = workspace.IntValue.Value
workspace.IntValue.Value = 50
print(int)
int = 92
print(workspace.IntValue.Value)
To fix the problem you either directly access the property and change it or have your variable hold the text label object.
local teams = game:GetService("Teams"):GetTeams()
local text = script.intermission.SurfaceGui.Frame.TextLabel
for _, team in pairs(teams) do
local players = game.Teams.Playing:GetPlayers()
print(#players)
if #players == 0 then
text.Text = 'test'
print('ok')
end
end
#Reference vs Value
It is important that you know the difference between a reference and a value.
##Reference
In Lua, for example, functions are passed by reference.
local func1, func2
func1 = function()
print(1)
end
func2 = function()
print(1)
end
local func1reference = func1
print(func1reference == func1)
print(func1 == func2)
print(function() end == function() end)
The func1 and func1reference variables both hold the same exact function. func2 is a different function from func1 even though it contains the same exact code. Remember, references.
##Value
But data like booleans and strings are simply passed by value.
local _string = "hello"
local _string_value = _string
_string = "ok"
print(_string_value)
print(_string)
local bool1 = false
local bool1_val = bool1
bool1 = true
print(bool1)
print(bool1_val)
Even though _string_value was set to _string, both variables have different memory and therefore changing one value does not change the other. The same happened for the boolean values, bool1_value never changed even after updating bool1.
######Hopefully this answered your question and if it did then don't forget to hit that accept button. If you have any other questions then feel free to leave them in the comments below.
2 comments
There should be a parent of the script and the intermission in the parent of the script. Maybe it should be script.Parent.intermission.SurfaceGui.Fram.TextLabel, or however many parents you have.
maybe use: local text = script.intermission:FindFirstChild("SurfaceGui.Frame.TextLabel.Text")