Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

If all die, script restart?

Asked by 6 years ago

Hi, I have a round based game that teleports you once the intermission is over. I am very beginner at scripting, so I do not understand some of this. I want to make it so if everyone dies then the script goes back to intermission.

Here is the code I have right now:

local status = game.ReplicatedStorage:WaitForChild("Status")

while true do
status.Value = "Intermission (10)"
wait(1)
status.Value = "Intermission (9)"
wait(1)
status.Value = "Intermission (8)"
wait(1)
status.Value = "Intermission (7)"
wait(1)
status.Value = "Intermission (6)"
wait(1)
status.Value = "Intermission (5)"
wait(1)
status.Value = "Intermission (4)"
wait(1)
status.Value = "Intermission (3)"
wait(1)
status.Value = "Intermission (2)"
wait(1)
status.Value = "Intermission (1)"
wait(1)
target = CFrame.new(-131.76, 18.66, -120.07) --could be near a brick or in a new area
for i, player in ipairs(game.Players:GetChildren()) do
    player.Character.Head.CFrame = target + Vector3.new(0, i * 5, 0)
    --add an offset of 5 for each character
end
function setTeam(player, teamName)
    player.TeamColor = game.Teams[teamName].TeamColor
    if player.Character then --Just in case the character doesn't exist for some reason
    end
end
for _, player in pairs(game.Players:GetPlayers()) do
    setTeam(player, "Playing")
end
status.Value = "Round in progress..."
wait(200)
status.Value = "Time is up!"
wait(4)
end

It would be greatly appreciated if you helped me. Thanks!

2 answers

Log in to vote
0
Answered by
valchip 789 Moderation Voter
6 years ago
Edited 6 years ago

I recommend you to learn how to script firstly from wiki, which recently changed to robloxdev.com. It is pretty clear your script is copy pasted. Also RIP grammar. Now let me give you a couple tips.

You do not have to fill a row with text and waits, you can just do this.

for i = 10, 1, -1 do
    status.Value = "Intermission..("..i..")"
    wait(1)
end

Another tip is using functions, also putting the whole script in a while true do loop will not fix anything.

EDIT: Some stuff from wiki is deprecated and do not learn from AlvinBlox.

0
I don't really understand... ElusiveEpix 2 — 6y
0
why wouldn’t they learn from alvin blox User#19524 175 — 6y
0
alvin blox is good duh, why wouldn't he learn from him? mixgingengerina10 223 — 6y
0
He just feeds you with scripts without telling you what the script does, when I was a beginner I used to watch him and he learnt me a bad habit, I just copied his scripts. valchip 789 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

To check if all players are dead, do this:

for _, player in next, game:GetService("Players"):GetPlayers() do
    if player.Character then
        if player.Character.Humanoid.Health == 0 then
            -- do code
        end
    end
end

Answer this question