PLEASE SOMEBODY HELP! (UNSOLVED) Please tell me how one of multiple choices are clicked? aSDnASDbsv,jh

Hello fellow developers and scripters! This is the second time I am posting my problem. Please help!

I want to create an NPC dialogue for many future projects, but I’m running into this obstacle:

From lines 26 to 46, I am having trouble looping through String Values, with all the NPC’s text and all the player’s responses/choices. (problem: How do I see if one of multiple options/choices are clicked?) So, I am trying to loop through all my choices and wait for one of them to be clicked to continue. It’s not working. I’ve done it before here:

but it doesn’t seem to work here.

The objects:

Dialogue Rules:

--[[

(Scroll right for the full description)

Explanation and Rules For The Dialogue Folder (for customization):

	-- Text --
	
	* Text: Text is what the NPC says. If there is another Text, a child of the main Text, that means that the NPC will say the first text, take a pause, and continue to the next.
	* ExitText: The Text of the NPC before the conversation or dialogue, if you want to call it that (a word that I like and overuse), ends.
	
	-- Choices --
	(Always numbered, unless there is one)
	
	* Choice: Choice is how you respond to the NPC's Text. There cannot be another Choice, a child of the Choice, like Text. Instead, there can be multiple choices under Text.
	* ExitChoice: The Choice that you make before the conversation ends. For example, "Goodbye!" or "Oh, I'll check it out'!" (There can only be one ExitChoices) . There can also be an ExitChoice and Choice in the same Text, but the ExitChoice must be numbered.

]]

-- SirHoog | September 25, 2022

The rules is just for other people

The script:

local talkEv = game.ReplicatedStorage.Talk
local transEv = game.ReplicatedStorage.TransScreen
local dText = script.Parent
local choiceButton = game.ReplicatedStorage.Choice
local mostRecentText
local mostRecentChoices
local mostRecentChoicePicked
local dialogueEnded = false

function typeWrite(text, speed, choiceDelay, choices) -- Tutorial by Alvin Blox - Youtube Tutorial: https://www.youtube.com/watch?v=RLXjta2F7Zw
	for i = 1, #text, 1 do
		dText.Text = string.sub(text, 1, i)
		
		wait(speed / #text)
	end
	
	wait(choiceDelay)
	
	for i, v in pairs(choices) do
		local newChoiceButton = choiceButton:Clone()
		
		newChoiceButton.Parent = dText.Parent.Choices
		newChoiceButton.Text.Text = v.Value
	end
	
	for i, v in pairs(dText.Parent.Choices:GetChildren()) do
		if v:FindFirstChild('Text') then
			print('test what????')
			
			v.Text.MouseButton1Up:Connect(function()
				
				print('test ahhhhhhhhhhh')
				if string.match(v.Name, 'ExitChoice') then
					dialogueEnded = true
					
					print('lol')
				else
					mostRecentChoicePicked = v
						
					print('sussy baja')
				end
				
				print('amogus testing')
			end)
		end
	end
end

transEv.OnClientEvent:Connect(function()
	talkEv.OnClientEvent:Connect(function(dialogue)
		wait(3)
		
		dText.Parent.Parent.Enabled = true
		
		mostRecentText = dialogue.Text
		mostRecentChoices = dialogue.Text:GetChildren()
		
		--for i, v in pairs() do
			typeWrite(dialogue.Text.Value, 2, 0.5, mostRecentText:GetChildren())
			
			print('asbdkjas whattttt amogus?')
			
			if dialogueEnded then
				return
			end
		--end
	end)
end)

Thank you in advance! But it is extremely late for me to stay longer, so if I don’t respond, you know. :slight_smile:

Can you show me what lines arent working, Im not sure if im using the right lines.

What? What do you mean? As in the line 26 and 46?

We can’t see lines numbers here

1 Like

Yes, I would like to see line 26 and 46 in the script. Its hard to find specific lines in devforum.

1 Like

It’s the for loop in the typeWrite function.

for i, v in pairs(dText.Parent.Choices:GetChildren()) do
		if v:FindFirstChild('Text') then
			print('test what????')
			
			v.Text.MouseButton1Up:Connect(function()
				
				print('test ahhhhhhhhhhh')
				if string.match(v.Name, 'ExitChoice') then
					dialogueEnded = true
					
					print('lol')
				else
					mostRecentChoicePicked = v
						
					print('sussy baja')
				end
				
				print('amogus testing')
			end)
		end
	end

Which loop? the ‘Text’ one or the dText.Parent.Choices:GetChildren() or the v.Text.MouseButton1Up one?

The dText.Parent.Choices:GetChildren() one. I sent it there:

Alright, first of all, why are you using scripts for a NPC dialogue if roblox has one built in? Secondly, are you sure it doesn’t have errors or it was randomly pasted from a old 2016 (or even older!) YouTube video because then it would be outdated.
If that doesn’t fix it, i have no idea.

1st: I don’t want to use the built in one. Ugly… I’m making a custom one (GUIs).
2nd: I wrote the code myself, but for the typewriting function, I followed an AlvinBlox tutorial; it still works.