Advertisement
Sufferrrrrr

natural disaster script

Jan 4th, 2025
2,819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. -- NATURAL SCRIPT
  2. -- credits: cat_givemyrobox
  3.  
  4. local disasters = {"Model"} -- List of disaster model names (case-sensitive). All disaster models must be in ReplicatedStorage.
  5. local countdownTime = 1 -- Time between disasters (in seconds).
  6. local disasterTime = 3 -- Time a disaster remains active (in seconds).
  7.  
  8. local countdownMessage = "The next disaster will occur in %s seconds." -- Message displayed between disasters. %s = seconds remaining.
  9. local disasterMessage = "Disaster: %s" -- Message displayed during disasters. %s = disaster name. Set to nil to disable.
  10.  
  11. local items = {}
  12.  
  13. -- Function to display a message to all players
  14. local function showMessageForAllPlayers(text, duration)
  15.     for _, player in pairs(game.Players:GetPlayers()) do
  16.         local playerGui = player:FindFirstChild("PlayerGui")
  17.         if playerGui then
  18.             local gui = playerGui:FindFirstChild("DisasterGui")
  19.             if gui then
  20.                 local label = gui:FindFirstChild("MessageLabel")
  21.                 if label then
  22.                     label.Text = text
  23.                     label.Visible = true
  24.                     task.wait(duration or 3)
  25.                     label.Visible = false
  26.                 end
  27.             end
  28.         end
  29.     end
  30. end
  31.  
  32. -- Populate the disaster items list.
  33. for _, disasterName in ipairs(disasters) do
  34.     local item = game.ReplicatedStorage:FindFirstChild(disasterName)
  35.     if item then
  36.         table.insert(items, item)
  37.     else
  38.         warn("Error! Disaster model '" .. disasterName .. "' was not found in ReplicatedStorage.")
  39.     end
  40. end
  41.  
  42. -- Function to choose a random disaster.
  43. local function chooseDisaster()
  44.     return items[math.random(#items)]
  45. end
  46.  
  47. -- Countdown logic.
  48. local function countdown(time)
  49.     while time > 0 do
  50.         showMessageForAllPlayers(string.format(countdownMessage, tostring(time)), 1)
  51.         time = time - 1
  52.     end
  53. end
  54.  
  55. -- Create GUI for each player.
  56. local function createPlayerGui(player)
  57.     local screenGui = Instance.new("ScreenGui")
  58.     screenGui.Name = "DisasterGui"
  59.     screenGui.Parent = player:WaitForChild("PlayerGui")
  60.  
  61.     local messageLabel = Instance.new("TextLabel")
  62.     messageLabel.Name = "MessageLabel"
  63.     messageLabel.Size = UDim2.new(0.8, 0, 0.1, 0)
  64.     messageLabel.Position = UDim2.new(0.1, 0, 0.8, 0)
  65.     messageLabel.BackgroundColor3 = Color3.new(0, 0, 0)
  66.     messageLabel.BackgroundTransparency = 0.5
  67.     messageLabel.TextColor3 = Color3.new(1, 1, 1)
  68.     messageLabel.Font = Enum.Font.SourceSansBold
  69.     messageLabel.TextSize = 24
  70.     messageLabel.Text = ""
  71.     messageLabel.Visible = false
  72.     messageLabel.Parent = screenGui
  73. end
  74.  
  75. -- Add points for surviving the disaster
  76. local function addPoints(player, points)
  77.     local leaderstats = player:FindFirstChild("leaderstats")
  78.     if leaderstats then
  79.         local pointsValue = leaderstats:FindFirstChild("Points")
  80.         if pointsValue then
  81.             pointsValue.Value = pointsValue.Value + points
  82.         end
  83.     end
  84. end
  85.  
  86. -- Create GUI for all players.
  87. game.Players.PlayerAdded:Connect(function(player)
  88.     createPlayerGui(player)
  89. end)
  90.  
  91. for _, player in pairs(game.Players:GetPlayers()) do
  92.     createPlayerGui(player)
  93. end
  94.  
  95. -- Main loop for disaster cycle
  96. while true do
  97.     countdown(countdownTime)
  98.  
  99.     -- Update leaderboard (if applicable).
  100.     for _, player in pairs(game.Players:GetPlayers()) do
  101.         addPoints(player, 50) -- Give points for surviving a disaster
  102.     end
  103.  
  104.     -- Select and activate a disaster.
  105.     local disaster = chooseDisaster()
  106.     if disaster then
  107.         local clone = disaster:Clone()
  108.  
  109.         if disasterMessage then
  110.             showMessageForAllPlayers(string.format(disasterMessage, clone.Name), 3)
  111.         end
  112.  
  113.         clone.Parent = workspace
  114.         clone:MakeJoints()
  115.         task.wait(disasterTime)
  116.         clone:Destroy()
  117.     else
  118.         warn("No disaster selected.")
  119.     end
  120. end
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement