How do I make it so that a disaster will end when everyone dies?
I got the code for the disaster end
Disaster ending when everyone dies code:
for _,v in pairs(game.Players:GetChildren()) do -- everything in players
if v.Character ~= nil then -- if the person exists
v.Character:BreakJoints -- kills
end end -- ends function
And the actual disaster script:
disasters = {"Baseplate"}
-- Disaster names are case-sensitive and all disaster models must be in the lighting
countdownTime = 17 -- The ammount of time to wait between each disaster.
disasterTime = 40 -- The ammount of time that the disaster will be in the game before it is removed.
countdownMessage = "The next disaster will occur in %s seconds." -- The message displayed between disasters. %s will be replaced with the number of seconds left.
disasterMessage = "Disaster: %s" -- The message displayed when a disaster occurs. %s will be replaced with the disaster name. Set to nil if you do not want a message
-- Unless you know what you are doing, please leave the below code alone.
items = {}
leaderboard = game.Workspace:findFirstChild("BTS Leaderboard") -- Used to work with my BTS leaderboard
local w = game.Workspace:getChildren()
for i=1,#w do
if w[i].Name == "leaderboard" and w[i]:findFirstChild("running") ~= nil and w[i]:findFirstChild("points") ~= ni then
leaderboard = w[i]
end
end
for i=1,#disasters do
local item = game.Lighting.Disasters:findFirstChild(disasters[i])
if item ~= nil then
item.Parent = nil
table.insert(items, item)
else
print("Error! ", disasters[i], " was not found!")
end
end
function chooseDisaster()
return items[math.random(#items)]
end
function EditGui(text)
local p = game.Players:GetChildren()
for i = 1, #p do
if p[i].PlayerGui.GameStats.Main.GameShow ~= nil then
p[i].PlayerGui.GameStats.Main.GameShow.Text = text
end
end
end
function sethint(text)
local hint = game.Lighting:findFirstChild("hint")
if (hint ~= nil) then
EditGui(text)
else
print("Hint does not exist, creating...")
h = Instance.new("Hint")
h.Name = "hint"
EditGui(text)
h.Parent = game.Lighting
end
--print("Hint set to: ", text)
end
function removeHint()
EditGui("")
hint = game.Lighting:findFirstChild("hint")
if (hint ~= nil) then hint:remove() end
end
function countdown(time)
sethint(string.format(countdownMessage, tostring(time)))
while (time > 0) do
wait(1)
time = time - 1
sethint(string.format(countdownMessage, tostring(time)))
end
removeHint()
return true
end
while true do
countdown(countdownTime)
if leaderboard ~= nil and leaderboard:findFirstChild("running") and leaderboard:findFirstChild("points") then -- For use with my BTS leaderboard.
leaderboard.points.Value = 20
leaderboard.running.Value = true
end
local m = chooseDisaster():clone()
if disasterMessage ~= nil then
local msg = Instance.new("Message")
msg.Name = "DisasterMsg"
EditGui(string.format(disasterMessage, m.Name))
msg.Parent = game.Lighting
wait(4)
msg.Parent = nil
EditGui("")
end
m.Parent = game.Workspace
m:makeJoints()
wait(disasterTime)
m:remove()
if leaderboard ~= nil then -- For use with the bts leaderboard.
leaderboard.running.Value = false
end
end
I've been trying to figure it out but it keeps breaking! Help?
Post.DLL has been successfully installed into this thread. |