Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- NATURAL SCRIPT
- -- credits: cat_givemyrobox
- local disasters = {"Model"} -- List of disaster model names (case-sensitive). All disaster models must be in ReplicatedStorage.
- local countdownTime = 1 -- Time between disasters (in seconds).
- local disasterTime = 3 -- Time a disaster remains active (in seconds).
- local countdownMessage = "The next disaster will occur in %s seconds." -- Message displayed between disasters. %s = seconds remaining.
- local disasterMessage = "Disaster: %s" -- Message displayed during disasters. %s = disaster name. Set to nil to disable.
- local items = {}
- -- Function to display a message to all players
- local function showMessageForAllPlayers(text, duration)
- for _, player in pairs(game.Players:GetPlayers()) do
- local playerGui = player:FindFirstChild("PlayerGui")
- if playerGui then
- local gui = playerGui:FindFirstChild("DisasterGui")
- if gui then
- local label = gui:FindFirstChild("MessageLabel")
- if label then
- label.Text = text
- label.Visible = true
- task.wait(duration or 3)
- label.Visible = false
- end
- end
- end
- end
- end
- -- Populate the disaster items list.
- for _, disasterName in ipairs(disasters) do
- local item = game.ReplicatedStorage:FindFirstChild(disasterName)
- if item then
- table.insert(items, item)
- else
- warn("Error! Disaster model '" .. disasterName .. "' was not found in ReplicatedStorage.")
- end
- end
- -- Function to choose a random disaster.
- local function chooseDisaster()
- return items[math.random(#items)]
- end
- -- Countdown logic.
- local function countdown(time)
- while time > 0 do
- showMessageForAllPlayers(string.format(countdownMessage, tostring(time)), 1)
- time = time - 1
- end
- end
- -- Create GUI for each player.
- local function createPlayerGui(player)
- local screenGui = Instance.new("ScreenGui")
- screenGui.Name = "DisasterGui"
- screenGui.Parent = player:WaitForChild("PlayerGui")
- local messageLabel = Instance.new("TextLabel")
- messageLabel.Name = "MessageLabel"
- messageLabel.Size = UDim2.new(0.8, 0, 0.1, 0)
- messageLabel.Position = UDim2.new(0.1, 0, 0.8, 0)
- messageLabel.BackgroundColor3 = Color3.new(0, 0, 0)
- messageLabel.BackgroundTransparency = 0.5
- messageLabel.TextColor3 = Color3.new(1, 1, 1)
- messageLabel.Font = Enum.Font.SourceSansBold
- messageLabel.TextSize = 24
- messageLabel.Text = ""
- messageLabel.Visible = false
- messageLabel.Parent = screenGui
- end
- -- Add points for surviving the disaster
- local function addPoints(player, points)
- local leaderstats = player:FindFirstChild("leaderstats")
- if leaderstats then
- local pointsValue = leaderstats:FindFirstChild("Points")
- if pointsValue then
- pointsValue.Value = pointsValue.Value + points
- end
- end
- end
- -- Create GUI for all players.
- game.Players.PlayerAdded:Connect(function(player)
- createPlayerGui(player)
- end)
- for _, player in pairs(game.Players:GetPlayers()) do
- createPlayerGui(player)
- end
- -- Main loop for disaster cycle
- while true do
- countdown(countdownTime)
- -- Update leaderboard (if applicable).
- for _, player in pairs(game.Players:GetPlayers()) do
- addPoints(player, 50) -- Give points for surviving a disaster
- end
- -- Select and activate a disaster.
- local disaster = chooseDisaster()
- if disaster then
- local clone = disaster:Clone()
- if disasterMessage then
- showMessageForAllPlayers(string.format(disasterMessage, clone.Name), 3)
- end
- clone.Parent = workspace
- clone:MakeJoints()
- task.wait(disasterTime)
- clone:Destroy()
- else
- warn("No disaster selected.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement