Cbrrah
(Cbrah)
January 11, 2022, 7:10pm
1
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:
All help is appreciated, thanks
NeoBuilds
(NeoBuilds)
January 11, 2022, 7:22pm
2
Thats because game.ReplicatedStorage.Timer:WaitForChild("TimeVal").Value
is nil. Try printing it.
Cbrrah
(Cbrah)
January 11, 2022, 7:27pm
3
Would you mind elaborating on that?
NeoBuilds
(NeoBuilds)
January 11, 2022, 7:29pm
4
Can you send me an explorer screenshot with it?
NeoBuilds
(NeoBuilds)
January 11, 2022, 7:31pm
6
Is it a NumnerValue or an IntValue?
NeoBuilds
(NeoBuilds)
January 11, 2022, 7:32pm
7
You can try doing this: game.ReplicatedStorage:WaitForChild(“Timer”):WaitForChild(“TimeVal”).Value
Cbrrah
(Cbrah)
January 11, 2022, 7:33pm
8
It’s a StingValue, I was previously using an IntValue but I got the same error.
NeoBuilds
(NeoBuilds)
January 11, 2022, 7:35pm
9
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)
pexf
(pexf)
January 11, 2022, 7:35pm
11
local TimeVal = game.ReplicatedStorage:WaitForChild('Timer').TimeVal
TimeVal.Changed:connect(function()
script.Parent.Text = TimeVal.Value
end)
Cbrrah
(Cbrah)
January 11, 2022, 7:37pm
12
Still getting the same error when I use that.
NeoBuilds
(NeoBuilds)
January 11, 2022, 7:37pm
13
Its not possible if you are talking about game not being fully loaded.
Cbrrah
(Cbrah)
January 11, 2022, 7:38pm
14
All the GUIS dissapear when the player respawns.
Update it whenever the value is changed then.
NeoBuilds
(NeoBuilds)
January 11, 2022, 7:40pm
16
Maybe disable ScreenGui.ResetOnSpawn then?
Cbrrah
(Cbrah)
January 11, 2022, 7:42pm
17
The text isn’t changing when using this script
Cbrrah
(Cbrah)
January 11, 2022, 7:43pm
18
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.
Cbrrah
(Cbrah)
January 11, 2022, 7:44pm
20
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