I have this script that chooses a random player to say a dialogue, but it also chooses a random player that is dead. I already made it where you’re on the Alive team but if you die you go to the Dead team. How do I make it where if the player dies he doesn’t get chosen?
--Variables
local remotes = game.ReplicatedStorage.Remotes
local CreateDialogueEvent = remotes.CreateDialogueEvent
local randomPlayerName
local randomPlayerId
local function getPlayerImage(player_id)
local content, isReady = game:GetService("Players"):GetUserThumbnailAsync(player_id, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
return content
end
local function getRandomPlayer()
local players = game.Players:getPlayers()
local number = math.random(1,#players)
local randomPlayer = players[number]
randomPlayerName = randomPlayer.Name
randomPlayerId = randomPlayer.UserId
end
--Actual Game Script
local function challenge_1()
local noimage = "rbxassetid://0"
wait(2)
CreateDialogueEvent:FireAllClients(getRandomPlayer(getPlayerImage),"Finally made it to the new house.")
end
local function challenge_2()
end
local function challenge_3()
end
local function challenge_4()
end
local function challenge_5()
end
local function challenge_ending()
end
local function startGame()
challenge_1()
challenge_2()
challenge_3()
challenge_4()
challenge_5()
challenge_ending()
end
wait(4)
startGame()