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

How do I make a last player standing script?

Asked by 6 years ago

So what I'm trying to do is make it so the when everyone but one person dies before the time's up, that person will be the winner or when 2 or more people survive the round ,they will be the winner.

The problem is, I'm extremely confused.

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

This should work

Script:

local diedEvent = Instance.new("RemoteEvent" , game.ReplicatedStorage)
diedEvent.Name = "Died"

local playersalive = game.Players:GetChildren()

diedEvent.OnServerEvent:Connect(function(plr)
    local plrname = plr.Name

    for i,v in ipairs(playersalive) do
        if v.Name == plrname then
            table.remove(playersalive , i)
        end
    end
end)

while true do
wait()
local index = #playersalive
if index == 1 then
print (playersalive)
end

LocalScript:


game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function() game.ReplicatedStorage.Died:FireServer() end)
0
This should all be one on the server side. User#5423 17 — 6y
0
not rlly DumbKickButt5588 167 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

This should require multiple scripts: 1. Insert a number value (call it Countdown) in workspace 2.Make a countdown for round script A. I won't provide you with one, customize it 3. In workspace, add a folder called Characters 3. Add script in it:

game.Players.PlayerAdded:connect(function(Player)
    local Plr = Instance.new("StringValue", script.Parent)
    Plr.Name = Player.Name
    Plr.Value = Player.Name
    Player.CharacterAdded:connect(function(Char)
        Char.Humanoid.Changed:connect(function(Change)
            if Change == "Health" then
                if workspace.Countdown.Value > 0 then
                    if Char.Humanoid.Health <= 0 then
                        Plr:remove()
                        if script.Parent:GetChildren()[3] ~= nil then
                            local Plrs = game.Players:GetChildren()
                            for i, v in ipairs(Plrs) do
                                if script.Parent:FindFirstChild(v.Name) ~= nil then
                                    --Player wins
                                end
                            end
                        end
                    end
                end
            end
        end)
    end)
end))

Thanks for providing me with this challenge, I'll use this script myself

Answer this question