So ive got a string value in replicatedstorage and it automatically changes it's value,But the timer that ive currently got is not working.
The script inside the textlabel(GUI),Is this :
while true do wait() script.Parent.Text = game.ReplicatedStorage["TIME_DRIVE"].CurrentTimer.Value end
Thats not working,Whenever i join the game the textlabel's text is completly blank. Any help?
Why not use a for
loop?;
for i = 10, 0, -1 do --10 = Countdown Time, 0 is the stopping point, -1 is the take away of i [10-1,9-1,8-1,ect.]; 'for' loops have many advantages aswell script.Parent.Text = i --This will display the Numbers; 10, 9, 8, 7, ect. wait(1) --Waits 1 second before going on to the next number end --This ends the code block for the 'for' loop
But, if you don't want to use a for
loop, then how about taking away the numbers in the Value using the while true do end
loop? Heres an example of what I mean;
local Time_Drive = game.ReplicatedStorage:WaitForChild("TIME_DRIVE") --This will wait until 'TIME_DRIVE' has loaded into ReplicatedStorage local TimeDrive = Time_Drive:WaitForChild("CurrentTimer") --This will wait until 'CurrentTimer' has loaded into 'TIME_DRIVE' while wait(1) do --Heres our 'while true do end' loop; this will loop the code every 1 seconds script.Parent.Text = TimeDrive.Value --This will display the Number/Time in 'CurrentTimer''s Value TimeDrive.Value = TimeDrive.Value - 1 --This will take away 1 from the Value; 10-1, 9-1, 8-1, ect. if TimeDrive.Value == 0 then --If the Value is/reaches to 0 then break --It'll break the loop end --This ends the code block for the 'if' statement end --This ends the code for for the 'while true do end' statement
Sorry if this was not a good explanation, or did not help, because I posted this at 11:57 PM.
EDIT
I just noticed the rest of your problem, theres a way to fix that, or, multiple ways, let me show you one using the WaitForChild
method;
local TimeDrive = game.ReplicatedStorage:WaitForChild("TIME_DRIVE") --'WaitForChild' waits until the Child type loads/gets added, and so, this will wait until 'TIME_DRIVE' loads, but if has already loaded then, it'll stop and go on with your code, kind of like the 'repeat until nil' loop and the 'FindFirstChild' method in my opinion :P local CurrentTimer = TimeDrive:WaitForChild("CurrentTimer") --The same thing happens here, it'll wait until 'CurrentTimer' loads
Hope this helped!
Use the Changed event that all StringValues have:
local timeDrive = game:GetService("ReplicatedStorage"):WaitForChild("TIME_DRIVE") local currentTimer = timeDrive:WaitForChild("CurrentTimer") currentTimer.Changed:connect(function(value) script.Parent.Text = value end)
http://wiki.roblox.com/index.php?title=API:Class/StringValue/Changed
Try putting it in workspace
while true do wait() script.Parent.Text = game.Workspace.Time_Drive.CurrentTimer.Value --You dont need to ["Time_Drive"] cause _ is recongnized unlike other special characters