Hello i Was Just Wondering How To Make Random Text Appear Out Of Varaibles With Strings I Made For A Death Screen
Text Variables Are Through Line 1 to 7
local textpreset1 = "What Led You Down This Path?" local textpreset2 = "Way To Go Buddy." local textpreset3 = "Welp That's NOT A Way To Do It." local textpreset4 = "Really Bro?" local textpreset5 = "Forgot To Put On A Vest?" local textpreset6 = "Do You Like Hurting Other People?" local textpreset7 = "Good Job. Just Good Job." -- died game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function() script.Parent.Sound:Play() script.Parent.Frame2.Visible = true script.Parent.Frame.Visible = true script.Parent.TextLabel.Visible = true script.Parent.TextLabel.TextTransparency = 1 wait(3) script.Parent.TextLabel.TextTransparency = 0 script.Parent.TextLabel.Text = (textpreset1 or textpreset2 or textpreset3 or textpreset4 or textpreset5 or textpreset6 or textpreset7) wait(9) script.Parent.TextLabel.Text = "" script.Parent.Frame.Visible = false script.Parent.Frame2.Visible = false end)
Please Leave Your Suggestions In The Comments.
You should put all your sentences in an array and use math.random
To randomize a sentance
local array = {“one”,”two”,”three”} local sentence = array[math.random(1,#array)] print(sentence)
Sentence will be one of the strings in the array.
Something you could do is put all of your text options in a table:
local deathMessages = {"What Led You Down This Path?", "Way To Go Buddy.", "Welp That's NOT A Way To Do It.", "Really Bro?", "Forgot To Put On A Vest?", "Do You Like Hurting Other People?", "Good Job. Just Good Job."}
And then run a script that will choose a random message:
local deathMessages = {"What Led You Down This Path?", "Way To Go Buddy.", "Welp That's NOT A Way To Do It.", "Really Bro?", "Forgot To Put On A Vest?", "Do You Like Hurting Other People?", "Good Job. Just Good Job."} deathMessages[math.random(1,#deathMessages)
Your death detection is incorrect. The gui will not appear in a local script and localPlayer will be nil in a server script. To fix this:
game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) char.Humanoid.Died:Connect(function() --Code end) end) end)
Your full script would go in ServerScriptService and would look like this:
local deathMessages = {"What Led You Down This Path?", "Way To Go Buddy.", "Welp That's NOT A Way To Do It.", "Really Bro?", "Forgot To Put On A Vest?", "Do You Like Hurting Other People?", "Good Job. Just Good Job."} game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) char.Humanoid.Died:Connect(function() local gui = game.ReplicatedStorage.DeathGui:Clone() --Put a ScreenGui in ReplicatedStorage and name it "DeathGui" gui.Parent = plr.PlayerGui gui.TextLabel.TextTransparency = 1 wait(3) gui.TextLabel.TextTransparency = 0 gui.TextLabel.Text = deathMessages[math.random(1,#deathMessages) wait(9) gui:Destroy() end) end) end)
You'll want to make you gui and then put it in ReplicatedStorage. Whatever you want to be seen, make visible.
I hope this answers your question.