function getRandomDialogue()
local dialogue = Dialogue[math.random(#Dialogue)]
if dialogue ~= LastDialogue1 and dialogue ~= LastDialogue2 and dialogue ~= LastDialogue3 and dialogue ~= LastDialogue4 and dialogue ~= LastDialogue5 and dialogue ~= LastDialogue6 then
LastDialogue6 = LastDialogue5
LastDialogue5 = LastDialogue4
LastDialogue4 = LastDialogue3
LastDialogue3 = LastDialogue2
LastDialogue2 = LastDialogue1
LastDialogue1 = dialogue
end
return dialogue;
end
This is supposed to prevent the same dialogue from being said. For some reason, it will apply the same strings to itself and still repeat strings back to back if lucky enough. Any help appreciated.
may try this it should cycle through use each one 1 time if i have it right then reset after all is used to do it again
local UsedDialogues = {}
function getRandomDialogue()
local dialoguekey = math.random(#Dialogue)
repeat
task.wait()
until not table.find(UsedDialogues,dialoguekey)
table.insert(UsedDialogues,dialoguekey)
if #UsedDialogues == #Dialogue then -- this will reset the table so they can all be randomly used again
UsedDialogues = {}
end
local dialogue = Dialogue[dialoguekey]
return dialogue;
end
or maybe this it will allow the dialogues to be said randomly without repeating the same one back to back
local LastDialogue
function getRandomDialogue()
local dialoguekey = math.random(#Dialogue)
repeat
task.wait()
until LastDialogue ~= dialoguekey
LastDialogue = dialoguekey
local dialogue = Dialogue[dialoguekey]
return dialogue;
end