Hello fellow developers and scripters!
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: read title) 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.