Random string selection not working correctly

This is actually an ez fix all you have to do is just

Function select () – blah blah
Local newIndex = Secrets(math.random(1,#Secrets)
Print (newIndex)
Continue your code
End

i see.
i watched a tutorial on how to use the modulo operator and and thought i had an excuse to finally use it.

:skull:

Well, I think it could be used in a similar scenario, where you don’t want a completely random sequence, but also not a completely arithmetic. You’d probably do #secrets % lastIndex though.

The local script is 357 lines, it’s the main dialogue MODULE that is over 1200 lines, 1281 to be exact. This is full of all the configurations for each NPC’s dialogue. Here’s an example:

EvDialogue = {

		DialogueInfo = {

			DialogueTitle = "Ev";
			DialogueContent = {"Welcome to... wherever we are. How can I help you?"}; -- First piece of content
			DialogueLayer = 1;

		};

		DialogueReplyInfo = {
			Reply1 = {
				ReplyTitle = "Who are you?"; -- Option
				ReplyContent = {"Me? I'm just another delver who was lucky enough to come back alive."}; -- Reply
				ReplyButtonLayer = 2;
			};

			Reply2 = {
				ReplyTitle = "How do I start a run?"; -- Option
				ReplyContent = {"By entering the elevator next to me. Good luck down there."}; -- Reply
				ReplyButtonLayer = 2;
			};
			-- More options to add, if any
					};

		DialogueSettings = {

			DialogueButton = game.Workspace.Lobby.Dialogue.Ev:WaitForChild("EvDialogue"); -- Trigger part 

			--// OTHER SETTINGS \\--

			TypeSpeed = 0.01; -- Speed for the dialogue typewriter.

			CustomCamera = true;
			CameraSettings = {
				CameraPart = game.Workspace.Lobby.Dialogue.Ev:WaitForChild("EvCam");
			};

			--// SOUNDS \\--

			TypewriterSound = "rbxassetid://6564956178"; 
			TypewriterVolume = 0.15;
			TypewriterRandomPitch = true;
			StartingContentSound = "rbxassetid://"; 
			ContentVolume = 0.1;

		};

	},

Further down is the one with the secrets function i want to call

Reply3 = {
				ReplyTitle = "Can you tell me a secret?"; -- Option
				ReplyContent = {"Hm... " ..VinnySecrets.selectSecret()..""}; -- Reply
				ReplyButtonLayer = 3;

Hope this clears some things up?

Cannot like that vinny,this will 100 percsnt not work

U cannot use a function inside a table ,i dont think they allow that,just use a varaible to do that

Ok, your dialogue module is static then. Your function is being called once the whole server since it runs it at the very beginning. You would have to, for that, change the dialogue after you use it to call the function again.

When you are displaying/using Reply3:

--code to write dialogue
Reply3.ReplyContent = {"Hm... " ..VinnySecrets.selectSecret()..""};

This way it resets each use.

I don’t understand. This is already how it’s formatted, am I missing something?

Yea, that’s the problem, you’re permanently formating the Reply3.ReplyContent at the beginning of the module script’s existence (when the server starts) which is why you change it by resetting it (calling the function again) after you use that secret.

1 Like

The dialogue functions are triggered every time the button is pressed, so in theory it should work if it’s being called at different times on separate occasions, i genuinely don’t know what’s going on here

It is? Can you print “Secret selected” every time it’s called to make sure it is? Because if it were, then it wouldn’t be the same every single time. Make run the dialogue multiple times making sure the bug you mentioned is in action and the print runs that many times.

Nevermind, you were right. I added the print statement and it only printed 4, the 4th string in the table once, and didn’t print any other results. Kinda lost here, lol

When are you displaying the dialogue? Maybe try what I said about resetting the replycontent after each use.