Advertisement
OnFireRobloxScriptin

Death Screen (Updated)

Nov 10th, 2024 (edited)
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. --//Variables
  2. local player = game:GetService("Players").LocalPlayer --Variable for the player
  3. local deathScreen = script.Parent.DeathScreen --Variable for the death screen
  4. local deathMessageLabel = deathScreen.DeathMessage --Variable for the text
  5. local character = player.Character --Variable for the player's character
  6. local humanoid = character:WaitForChild("Humanoid") --Variable for the character's Humanoid
  7.  
  8. --//Death Messages
  9. local deathMessages = { --Creates a new list to hold our death messages
  10.     "You died!", --For each death message, put text inside "" then follow it with a comma
  11.     "Try harder text time!", --Use this template if you are confused: "Death message here",
  12.     "Ouch! That must've hurt!",
  13.     "You met your match.",
  14.     "Respawning... try again!",
  15.     "Don't give up!",
  16.     "Almost had it!",
  17.     "Rest in peace... for now!",
  18.     "Yikes! That was rough!",
  19. }
  20.  
  21. --//Display Death Messages
  22. local function onPlayerDeath() --Function for displaying the death message
  23.     local randomMessage = deathMessages[math.random(1, #deathMessages)] --Chooses a random death message from our list
  24.     deathMessageLabel.Text = randomMessage --Changes the text to the random death message
  25.    
  26.     deathScreen.Visible = true --Makes the death screen visible to the player
  27.     task.wait(3)  --*When the player respawns, the death screen will automatically disappear. But this is to make sure just in case they don't for some reason
  28.     deathScreen.Visible = false --Makes the death screen invisible to the player
  29. end
  30.  
  31. humanoid.Died:Connect(function() --When the humanoid (the player in the game) dies
  32.     onPlayerDeath() --Call the function onPlayerDeath which will display the death screen
  33. end)
  34.  
  35. --If your death screen is already visible before you die, make sure you disable "Visible" under the death screen Frame!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement