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

Players don't respawn after dying?

Asked by 10 years ago

Hi. I've created a custom spawning system, however I've discovered a flaw. When a player dies and they're still on the team, they don't spawn back at where the bricks where they're supposed to spawn at?

How do I fix this problem? Thank you.

function customspawn()
local redcolor = BrickColor.new("Bright red")
local blucolor = BrickColor.new("Bright blue")
local curmap = Workspace.MapHolder:GetChildren()[1]
for i,v in next, game.Players:GetPlayers() do
    if curmap then
        if v.TeamColor == redcolor then
        local reds = curmap.redspawns
        local spawn1 = reds:GetChildren()
        local spawn = spawn1[math.random(1,#spawn1)]
        v.Character:MoveTo(spawn.Position)
    elseif v.TeamColor == blucolor then
        local blus = curmap.bluespawns
        local spawn2 = blus:GetChildren()
        local spawn = spawn2[math.random(1,#spawn2)]
        v.Character:MoveTo(spawn.Position)
    end
end
end
end

2 answers

Log in to vote
1
Answered by 10 years ago

You could use the Died event of the Humanoid object.

    repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
    local player = game.Players.LocalPlayer
    local char = player.Character   
    local humanoid = char.Humanoid

    humanoid.Died:connect(function()
        local redcolor = BrickColor.new("Bright red")
        local blucolor = BrickColor.new("Bright blue")
        local curmap = Workspace.MapHolder:GetChildren()[1]

        if player.TeamColor == redcolor then
             local reds = curmap.redspawns
                 local spawn1 = reds:GetChildren()
                 local spawn = spawn1[math.random(1,#spawn1)]
        elseif player.TeamColor == blucolor then
            local blus = curmap.bluespawns
                local spawn2 = blus:GetChildren()
                local spawn = spawn2[math.random(1,#spawn2)]
                v.Character:MoveTo(spawn.Position)
        end
    end)

Use a LocalScript

Ad
Log in to vote
0
Answered by 10 years ago

Try adding v:LoadCharacter() The character might not be existent if they died.

0
No, the spawns are not SpawnLocations. They are bricks since a ROBLOX glitch broke the spawn locations. truefire2 75 — 10y

Answer this question