tostring() will just make it say “nil”.
Why is this not working.
There is a wait (0.1), a lot can happen during that 0.1 second of wait. Something turned it nil I suppose.
Since it prints before the wait try just storing it.
local accouncementStore = info.Annoucnent
wait(0.1)
--set the .Text
Try removing the wait(0.1), this is very odd.
Where is the “info” variable made?
I’m sorry but you all told it wrongly
wait()
is depcreated
task.wait()
is now live
Use task.wait() and try to run a print function at start and end of that line to check for errors
You can also try pcall function
You should not use pcall here.
Having errors in your code is a sign that, well, something about your code is not designed well and so you should fix it.
Silencing them makes it so that flaws in your system don’t get shown which can cause even more problems in the future.
You should really only use pcall in situations where you are doing some sort of web request where a dozen things could go wrong and you don’t really have much control over it.
I want to know what exactly did you print? did you print the table of ‘info’, if so please click the arrow where it shows the resulting print and let us see what the contents are, my guess, info.Announcement is infact nil
Yes, but uh you know you can also use pcall in huge scripts where tons of things go wrong
This is a very common misconception I see with things being deprecated
You should probably understand why something is deprecated in the first place before suggesting this as an all in one fix to a problem.
The issue with wait() is that it throttles from the task documentation as well.
Unlike the global
wait
, this function does not throttle and guarantees the resumption of the thread on the first Heartbeat that occurs when it is due. This function also only returns the elapsed time and nothing else.
This throttling is mostly visualized when using wait() a lot in a while loop seen in the youtube video below:
This should not apply to the current problem when wait(0.1) is only used once.
It will still cause the same issues which is displayed here which is caused by a delay code execution and delay in accessing the info.Announcement:
→ Info.Announcment is accessed, prints data as expected, a table and the value 5 which is needed
–>then there is a wait(0.1) which delays the execution of the code
→ Info.Announcement becomes nil in between here due to code execution order,
perhaps in another script:
someone presses a button during the 0.1 wait time lets say which triggers this nil,
A while loop updating info.Announcement accidently updates during this time period making it nil
–>the wait(0.1) resumes
–>Then this Info.Announcement becomes nil causing a nil error
Using task.wait will still cause the code execution to be off from the moment the table is accessed.
Consequently, I propose this to allow the delay to update the UI with the current values possible
local data = info.Announcement
task.delay(0.1, function()
makeMsg.Text = tostring(data)
end)
This will remove the wait(0.1) and prevent the thread from delaying while also allowing a 0.1 second delay for the message to be updated presumably for Aesthetics which the writer intended to display one message first then switch to the next message.
Uh, look the task.wait() is a global variable it does not deals with script, even if its destroyed, while wait() is a local variable, it will stop working and that how it works
Also the error is about string expected
tostring(nil) = nil
He should give some string or number to change it to string, else it returns nil, and you cannot keep a text as nil, you can only keep it blank ""
, attempting to keep textlabels as nil will also cause an error
If tons of things are erroring chances are things are breaking, so it wouldn’t make sense to silence useful errors as an attempt to fix bugs.
Both task
and wait
are globals, task
is a library and wait
is a function.
What do you mean it’s a variable?
I mean its a local function of the script
wait
isn’t local? It’s a global built-in function, which is why it’s colored blue.
Wdym it’s local if it’s local then it’d been defined “IN” the script. As @Judgy_Oreo said it’s global.
Hey so this is actually what I am doing here. I am sure it has something to do with the way I am doing things too but:
In a server script I am using a RemoteEvent to communicate with the players like so:
local communicator = script.RemoteEvent
local countdownTime = 5
communicator:FireAllClients("GAME", true,
{
--Command: (items needed)
Command = {"PRE-GAME-COUNTDOWN", true};
Announcement = countdownTime,
}
)
In a local script this is what happens:
local contents = {}
["GAME"] = function(bool, information)
info = information;
if bool == true then
if contents["GAME"] == nil then
contents["GAME"] = {
Bool = false; --Used to determine if the game is off or not.
GAME_OBJS = {}; --ALL of the game objs.
game_Functions = { --ALL of the game functions.
["PRE-GAME-COUNTDOWN"] = function(bool)
if bool == true then
print(info, info.Announcement)
wait(0.1)
local textSize = makeMsg.TextBounds.Y
makeMsg.Name = info.Announcement
makeMsg.TextScaled = false
--etc
end
end,
}
end
contents["GAME"].game_Functions[info.Command[1]](info["Command"][2])
end
end,
Now the reason I have
info = information;
as a global variable is because if I keep it local, the table would never change and the “PRE-GAME-COUNTDOWN” will only read the first command that is ever sent rather than reading each new command that comes through with all of the new variables. It starts to act funky after I put the “wait(0.1)”.
Just remove the wait(0.1)
since something is making the value nil within that timeframe. Although if you don’t want to delete the wait(0.1)
, then make a local variable that stores the data and after 0.1 seconds you will set the name to the stored variable
print(info, info.Announcement)
local infoAnnounce = info.Announcement
wait(0.1)
local textSize = makeMsg.TextBounds.Y
makeMsg.Name = infoAnnounce
makeMsg.TextScaled = false
makeMsg.TextWrapped = false
makeMsg.TextSize = textSize
makeMsg.Text = infoAnnounce
print(info.Announcement, infoAnnounce)
If it doesn’t work, try to use tostring()
when using the infoAnnounce variable