Hello! I am working on a game that involves an area that has a linear path and storytelling. I ran into an issue while trying to make the third-person dialogue/guide system.
When receiving the checkpoint number and searching the response array (PathList) for the correct string with the number (checkpointval/cnum), it will not print itself in the TextLabel and will not activate the TypeWriter module.
I have tried various solutions in an attempt to “convert” this array value (which is a string) into a string. All of these have inevitably failed. I searched online and in the DevForum and have read many Developer Hub articles on tables and arrays, but have yet to come to a compromise. I am using this as a last resort to see if I can somewhat fix the problem before having to rewrite the system.
PathList:
local PathList = {
"Good. Keep going.", -- Prints if cnum is 1
"There seems to be a point of interest on the horizon. Investigate the matter.", -- Prints if cnum is 2
"The path ends here, it seems. Try to find your way down the ravine.", -- Prints if cnum is 3
}
(Clipped LocalScript) Receives RemoteEvent values and searches array. Then, prints array string onto TypeWriter text.This LocalScript is located in the PlayerGui. Just noting this in the case of an issue.
cbe.OnClientEvent:Connect(function(checkpointval) -- Receives checkpoint number (1, 2, or 3)
print("Recieved")
cnum = checkpointval
upd:Fire()
end)
upd.Event:Connect(function() -- Updates TextLabel with new string
print("Updating")
cTween:Play()
tTween:Play()
wait(0.125)
Label.Text = ""
wait(0.125)
TypeWriter.typeWrite(Label, PathList[cnum]) -- PathList[cnum] errors nil here, but not when using print()
end)
(Errors in TypeWriter line)
Solutions I have tried:
table.concat
Converting PathList[cnum] into a variable, then calling for that variable
All help is appreciated. This is my first time scripting a complete game, so I am somewhat new to all of this. Please ask me if you have any questions.
PathList may be recognized as nil if it doesn’t fit the entire scope of the script. Have you made sure local PathList is not declared inside a function or any other place that will limit its scope?
The typeWrite function can be found in the Developer Hub article, Animating Text. I will try to see if the tostring(PathList[cnum]) thing will work. Thank you for the suggestion!
Update: The line does not error anymore, however, it only types the word “nil”. I am guessing it made progress into converting it into a string, but not the actual value.
Reference:
Oh that sucks, don’t know why it’s doing this, but try to send cnum through the module, and select the right string in that module. Also see if sending a generic string like ”Hello World!” works.
Overall, I wouldn’t use this method. Having a global cnum variable is pointless, considering that you’re using BindableEvents. I would suggest doing this instead:
Thank you for the improvement. As anticipated, however, it has not solved the problem. It errors Argument 2 missing or nil. I do appreciate your advice on my code, though!
I have resolved this issue by obtaining the string text directly from the object that fired it (sends StringValue value when fired), then printing that string. This is in replacement of obtaining a number value from the object name (1), then searching the array for the object’s string attachment. It is less efficient, but works just fine.