Weirdest error of all mankind (.Text doesn't exist even though it does)

Hello! I got an error.


However, .Text is a thing as seen here:
image
Here is the code:

local Player = game:GetService("Players").LocalPlayer
local PlayerData = Player:WaitForChild("PlayerData")

local function CommaValue(UnconvertedValue)
	local FormattedValue = string.gsub(UnconvertedValue, "^(-?%d+)(%d%d%d)","%1,%2")
	return FormattedValue
end

script.Parent.Text = CommaValue(PlayerData:GetAttribute("MultiplayerWins")) -- This here is line 9

PlayerData.AttributeChanged:Connect(function()
	script.Parent.Text = CommaValue(PlayerData:GetAttribute("MultiplayerWins"))
end)

If you know how to fix, please let me know. Thanks! WE

The error doesn’t mean that text doesn’t exist, it just says script.Parent is nil.

but why is it nil? Should I try adding this to the top of the script?

repeat game:GetService("RunService").RenderStepped:Wait() until game:IsLoaded()

What is the script Parented to?

It’s parented to the text label.

try putting that line of code you wrote in your second reply

script.Parent.Text = CommaValue(PlayerData:GetAttribute("MultiplayerWins")) -- This here is line 9

Try this before you set that text

if not script.Parent then
    repeat wait() until script.Parent
end

Still, that variable will hold nil tough.

Did your solution except for using RenderStepped:Wait(), and it worked. However, this is similar, and it doesn’t error:

local Player = game:GetService("Players").LocalPlayer
local Points = Player.leaderstats.Points

local function CommaValue(UnconvertedValue)
	local FormattedValue = string.gsub(UnconvertedValue, "^(-?%d+)(%d%d%d)","%1,%2")
	return FormattedValue
end

script.Parent.Text = CommaValue(Points.Value)

Points.Changed:Connect(function()
	script.Parent.Text = CommaValue(Points.Value)
end)

Do you know why?

I don’t know what you mean, can you go a little bit detail?

The original wins system was just a copy and paste of that script, but made for Points. Do you know why it would error but not the solution script?

The error is “Attempt to index nil with “Text”” as well, right?

There is no error with this one. It works just fine.

Is this run in the server? Or client?

This script runs on the Client.

I didn’t see anything wrong. I’m not sure what is going on. Is your script running?

Yes. Everything is fine. It is just that this script works for 1 stat with no errors, but not another stat.

local Player = game:GetService("Players").LocalPlayer
local Points = Player.leaderstats.Points

local function CommaValue(UnconvertedValue)
	local FormattedValue = string.gsub(UnconvertedValue, "^(-?%d+)(%d%d%d)","%1,%2")
	return FormattedValue
end

script.Parent.Text = CommaValue(Points.Value)

Points.Changed:Connect(function()
	script.Parent.Text = CommaValue(Points.Value)
end)

This is very weird, I don’t know what happened. Sorry, I can’t help you with this one.

1 Like