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

How do you make a script that teleports you back when the game ended?

Asked by 6 years ago

Well I have a really big script so this is just one piece of it

status.Value = "Be The Last Standing!"
if status.Value then
    game.Workspace.Sound:Stop()
end
wait(4)
for i = 196,0,-1 do -- You can adjust the #196 to how long you want the round to last.
    if i == 0 then
        status.Value = "Time is up!"
        wait(3)
        break
    end
    wait(1)
    if #_G.gameplayers == 1 then
        for i, v in pairs(_G.gameplayers) do
            if v ~= nil then
                status.Value = v.." Won The Game!"
                game.Players[v].leaderstats.Cash.Value = game.Players[v].leaderstats.Cash.Value + 15 -- The #15 will be how much credit or cash is awarded to the player if there was only one player teleported.
                break
            end

        end
        break
    else
        status.Value = i.."..Seconds Remaining!"
    end
end
    for i, player in ipairs(game.Players:GetPlayers()) do
    if player.Character then
        local hum = player.Character:FindFirstChild('Humanoid')
        if hum then
            hum.Health = 0
        end
    end
end
mapstorage:ClearAllChildren()

wait(5)
end

I tried the code

 for i, player in ipairs(game.Players:GetPlayers()) do
    if player.Character then
        local hum = player.Character:FindFirstChild('Humanoid')
        if hum then
            hum.Health = 0
        end
    end

to spawn the characters back into the lobby but it didn't worked. Any solutions ???

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

You could loop through all players and call player:LoadCharacter() to respawn the player without killing them if you wanted to.

local players = game.Players:GetPlayers()

for index = 1, #players do
    players[index]:LoadCharacter()
end
Ad

Answer this question