Why won't the text on my textlabel update with this script?

local textLabel = script.Parent

local function update()

	textLabel.Text = "test"
	
end

It’s a local script, if that helps

Example of a script that DOES work, but only if it’s at the top, disallowing me from adding any functions into it.

while wait(0.1) do
	script.Parent.Text = "test" 
end
1 Like
local function update()
	textLabel.Text = "test"	
end

while task.wait() do
   update()
end
1 Like

With the script you provided, you never call the function update().

1 Like

This still won’t work if it’s placed under variables

1 Like

Can you show the full script? My script should work.

1 Like
local textLabel = script.Parent

local function update(text)
      textLabel.Text = text
end

update() --put what u would want to make it say in this update bracket.
1 Like
local player = game.Players.LocalPlayer

local leaderstats = game:GetService("ServerScriptService"):WaitForChild("leaderstats")

local cash = leaderstats:WaitForChild("Coins")

local AbbreviateX = require(game.ReplicatedStorage.AbbreviateX)

local Output = AbbreviateX:Abbreviate(100000000, 1)

local textLabel = script.Parent

local function update()

textLabel.Text = Output.Value

end

while task.wait() do

update()

end

It’s supposed to be a number abbreviation script

1 Like
local player = game.Players.LocalPlayer

local leaderstats = player:WaitForChild("leaderstats")

local cash = leaderstats:WaitForChild("Coins")

local AbbreviateX = require(game.ReplicatedStorage.AbbreviateX)

local Output = AbbreviateX:Abbreviate(100000000, 1)

local textLabel = script.Parent

local function update()
   textLabel.Text = Output
end

while task.wait() do
   update()
end
1 Like

I doubt that the modulescript that you’re requiring returns the abbreviated number as an instance. try removing the Output.Value and have it just be Output

2 Likes

It’s still coming back as the default textlabel text, but no errors are showing up. I tried both a normal and local script on the text label

1 Like

Where did you place your LocalScript under? Obviously it’s a TextLabel, but is it a SurfaceGui? If so, is it in StarterGui or the Workspace?

1 Like

The localscript is under a text label, which is in a screengui in startergui

1 Like

Are you sure that these Instances are being created properly with the same name?

1 Like

Absolutely sure. The coins variable isn’t even being used in the text change script

1 Like

I realized I previously replied to the wrong person.

This won’t work ever, because ServerScriptService is inaccessible to LocalScripts. Maybe you meant what Lostude shared:

1 Like

The script worked perfectly fine as a local script with this code:

while wait(0.1) do
	script.Parent.Text = "test" 
end

1 Like

This script should work in a local script, also. If it doesn’t I’m unsure as to why.

1 Like

Have you tried using the debugger to step through the code and find out what’s wrong?

Place a breakpoint next to the first line and use “Step Over” and “Step In” on the Ribbon (at the top) to help you

1 Like

I got an error: Players.Paracolity.PlayerGui.gui.coinDisplay.Script:3: attempt to index nil with ‘WaitForChild’
But it still doesn’t explain why the text wont show up