So, I’m trying to a dialog script where a random player is picked to be speaking. But the problem is, sometimes the same person can be picked twice to speak. Leading to problems like “user1: I like cheese” “user1 (again): no! I disagree!”
Unless you’re playing solo, this can be a problem.
How do I fix this?
local function getRandomPlayer()
local players = game.Players:getPlayers()
local number = math.random(1,#players)
local randomPlayer = players[number]
randomPlayerName = randomPlayer.Name
randomPlayerId = randomPlayer.UserId
game.Workspace.Values.CurrentSpeaker.Value = randomPlayerName
end
—This is the how getRandomPlayer() works v
local function intro()
local NPC_Image = "http://www.roblox.com/asset/?id=13916757036"
CreateDialogueEvent1:FireAllClients(NPC_Image,"Welcome, children, To the best forest camp you will ever have in your life!")
game.Workspace.Values.CurrentSpeaker.Value = "Guide"
wait(9)
getRandomPlayer()
CreateDialogueEvent1:FireAllClients(getPlayerImage(randomPlayerId), "This is gonna be the best day ever!")
game.Workspace.Values.CurrentSpeaker.Value = randomPlayerName
wait(5)
getRandomPlayer()
CreateDialogueEvent1:FireAllClients(getPlayerImage(randomPlayerId), "I know right!? I love camping!")
game.Workspace.Values.CurrentSpeaker.Value = randomPlayerName
wait(7)
local NPC_Image = "http://www.roblox.com/asset/?id=13916757036"
CreateDialogueEvent1:FireAllClients(NPC_Image,"Feel free to explore the campus!")
game.Workspace.Values.CurrentSpeaker.Value = "Guide"
wait(50)
game.ReplicatedStorage.TransitionEvent:FireAllClients()
end
``