Please help with this error

I have a script that checks the value of a StringValue and applies it to text.
However, when you die, the script errors and stops working.

Script:

warn("Timer loaded.")
while task.wait(.1) do
	script.Parent.Text = game.ReplicatedStorage.Timer:WaitForChild("TimeVal").Value
end

Error:
Client - Timer:1 13:08:00.525 Players.CbrahDev.PlayerGui.TimeGUIS.Timer.Time.Timer:3: attempt to index nil with 'Text' - Studio

The script is a local script inside the text:
image

All help is appreciated, thanks :slight_smile:

Thats because game.ReplicatedStorage.Timer:WaitForChild("TimeVal").Value is nil. Try printing it.

Would you mind elaborating on that?

Can you send me an explorer screenshot with it?

image
Does that work?

Is it a NumnerValue or an IntValue?

You can try doing this: game.ReplicatedStorage:WaitForChild(“Timer”):WaitForChild(“TimeVal”).Value

It’s a StingValue, I was previously using an IntValue but I got the same error.

This may help:

warn("Timer loaded.")
while task.wait(.1) do
	script.Parent.Text = game.ReplicatedStorage:WaitForChild("Timer"):WaitForChild("TimeVal").Value
end

You’re getting that error because the TextLabel is not there when you try and change its text. You can:

Add this after the while task.wait(.1) do:

--while task.wait(.1) do
if script.Parent == nil then return end
--script.Parent.Text = game.ReplicatedStorage.Timer:WaitForChild("TimeVal").Value
--end

Or, what I would recommend
Change the text when the character spawns. Then everytime the “TimeVal” is changed, update the text.

script.Parent.Text = game.ReplicatedStorage.Timer:WaitForChild("TimeVal").Value

game.ReplicatedStorage.Timer:WaitForChild("TimeVal").Changed:Connect(function()
-- what todo everytime the TimeVal is changed (script.Parent.Text = game.ReplicatedStorage.Timer:WaitForChild("TimeVal").Value)
end)
local TimeVal = game.ReplicatedStorage:WaitForChild('Timer').TimeVal

TimeVal.Changed:connect(function()
script.Parent.Text = TimeVal.Value
end)

Still getting the same error when I use that.

Its not possible if you are talking about game not being fully loaded.

All the GUIS dissapear when the player respawns.

Update it whenever the value is changed then.

Maybe disable ScreenGui.ResetOnSpawn then?

The text isn’t changing when using this script

It’s not updating on the client side.

Are you changing the StringValue on the server? It should register whenever the value changes for the client.

Yes, I’m changing the value on the server.
Edit: the script shown at the top is working perfectly fine except for when the player resets