#check if there is known in a team and doing an action if there ae no players in the team

1 messages · Page 1 of 1 (latest)

tight robin
#

hi i cant figure out how to check if there are still players in a team or if all have died or something a need to know so i can end the round if all in one team is less then 1 or i other word non are in the team

marble bolt
#

Humanoid.Died

ocean badger
tight robin
late pelicanBOT
#

studio** You are now Level 8! **studio

marble bolt
#

do an if check

tight robin
#

Kk

#

Il try lol

#

XD

nimble crystal
tight robin
tight robin
#

@nimble crystal im confused

devout crystal
# tight robin <@1435749227270766773> im confused
local Players = game:GetService("Players");

local Teams = game:GetService("Teams");

local function AlivePlayers()
    return #Teams.Alive:GetPlayers();
end

local aliveCount = AlivePlayers();

if aliveCount <= 0 then
    print("No players are alive");
else
    print(aliveCount.." players are still alive.");
end```
late pelicanBOT
#

studio** You are now Level 2! **studio

tight robin
tight robin
#

@devout crystal

ocean badger
tight robin
#

O ok

tight robin
tight robin
#

I’m not at my computer right know so I will in a little bit later

#

Sorry

tight robin
#

local Players = game:GetService("Players");

local Teams = game:GetService("Teams");

local function AlivePlayers()
return #Teams.Survivors:GetPlayers();
end

local aliveCount = AlivePlayers();

if aliveCount <= 0 then
player.Team = Teams.Spectators
else
print(aliveCount.." players are still alive.");
end

tight robin
ocean badger
#

but it wont change the players team to spectator if thats a local script

#

u need to send a remote to server

#

and then change plr team

tight robin
#

so the only thing i must chang is the action?

#

and move the corint action to a difrent scrept and replas tomtheng els in its oreganule spot?

tight robin
#

@ocean badger hello?

tight robin
#

what must i chang is what im saying

#

i confus and farly new

tight robin
ocean badger
#

yes

#

ur code should work

#

but it wont change the players team to a spectator team if its a local script

#

u have to send a remote to the server and then change the players team on the server

tight robin
#

so how do i send a remote?

ocean badger
#

create a remote event

tight robin
#

nvm

tight robin
#

do i put it insied the if condshen?

ocean badger
tight robin
#

Kk

tight robin
#

@ocean badger ?

#

it is in the server scripted tho

tight robin
#

I don't get you response

#

Wdym

#

😭

#

@elder heath wdym XX

elder heath
tight robin
#

why did you reply with a dog eating popcorn XX

elder heath
elder heath
elder heath
# tight robin Then how do I do an action of its 0 sorry XD 😅

because basically you just loop through all players in the team and check if their humanoid is alive (not in dead state, hp above 0 etc), then you can either just count how many alive players there are in the team, or use this to construct another table of only alive or only dead players who are in that team. lots of other stuff you can do too, like if a player should be kicked from their team into spectator when they die, you can connect to their humanoid died. a lot of the work here is keeping track of all the teams, where the players are, and connecting to each of their humanoids. can be a bit tricky if you're a beginner, so what stage you think you'd be at? ..... or you can wait for someone to come back in here to continue spoonfeeding up to you dogepopcorn

tight robin
#

i alred send evry player that dies to the spectater team

#

but the ramaining or the other living team is the isue so i neet to chech if a team is empte

elder heath
tight robin
#

baist on what i said what grateak do you have for me

tight robin
elder heath
# tight robin i alred send evry player that dies to the spectater team

well if you do that, you can just check the remaining number of players in the team. depends a lil on when you do it. if you check remaining team members before kicking the dead player to spectator, then if the team count is 1 you know it is the last player. if you check the remaining team members after kicking the dead player, then the team count will be 0 if its the last player.

#

logical deductions and inferences like this is how you formulate a script

tight robin
#

also what tipe of cript needs this code becus i am confus cus someone sead it was in the rong script and needed to be in the server script but it was as faar as im awer in the server script

#

also whatt dus dis mean @elder heath

elder heath
#

i can tell you what you could do, but i won't tell you what you should do.

tight robin
#

o ok

elder heath
#

spoonfeeding is really bad for the person being spoonfed

#

like you almost may as well just use ai at that point, it's the same level of taught helplessness

#

extremely short term benefit yes, but with detrimental long term cost.

tight robin
elder heath
#

it's like you can have $1 today, or $100 in 10 days. the choice is obvious, but if you're desperate for that $1 you may be blinded to the $100

tight robin
#

ya fair\

elder heath
#

it is very bad for you

#

(i'm aware this isn't obvious)

tight robin
#

im just confused abut why they said it was rond then prosedid to tell me to put it were it was

elder heath
#

tbh just remove their code entirely and go back to what you had before you put in their code

tight robin
#

so im confued now and dont know if im rong or not

elder heath
#

and now you're left begging "where do i put that" and "what do i do now", it's incredibly harmful to new developers

tight robin
#

why are they helping people if they dont know crying

elder heath
#

so trust me when i say, if you want to actually be a scripter, i suggest you discard the code they gave you and come up with your own code, even if that code is bad -- it's far, far more important that you understand what your code is doing, even if it's done wrong, compared to doing it right the first time.

#

no one ever does it right the first time. that's a natural part in learning. accept the mistakes you will make.

#

and you will make many.

#

no expert in any field is an exception to this.

elder heath
#

sometimes the spoonfeed is correct the first time, but even if it were, you'd only be back tomorrow because you never earned the knowledge and understanding you should have gained from solving this problem yourself, and understanding how these things work

#

it's like if you went to play bloxfruits, and all you did was follow around someone who is max level and they did all the work, and then they left and you never saw them again, you would have no idea how to play bloxfruits, you'd pretty much have to start from the beginning again. that's what i mean.

#

so.

elder heath
#

without their additions

tight robin
elder heath
tight robin
#

i forggot how to do the cool thing to cover it and make it ezyer to read

tight robin
#

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local CoreEvent = ReplicatedStorage:WaitForChild("CoreEvent")
local RoundTimer = ReplicatedStorage:WaitForChild("RoundTimer")

local RoundStarted = false
local Break = false
local Corrupter

local intermissionTime =45 --in seconds
local RoundTime =180 --in seconds

local function Countdown(time)
RoundTimer.Value = time
for i = time, 0, -1 do
RoundTimer.Value = i
if #Players:GetPlayers() < 2 then
CoreEvent:FireAllClients("Round", "Clear")
Break = true
return
end
task.wait(1)
end
end

#

local function StartRound()
RoundStarted = true

CoreEvent:FireAllClients("Round", "Start")
Countdown(intermissionTime)
if Break then
    Break = false
    return
end

local players = Players:GetPlayers()
Corrupter = players[math.random(1, #players)]
Corrupter.Team = Teams.Corrupter
Corrupter.Character:PivotTo(workspace.CorrupterSpawn.CFrame + Vector3.new(0,1,0))

for _, player in ipairs(players) do
    if player ~= Corrupter then
        player.Team = Teams.Survivors
        player.Character:PivotTo(workspace.SurvivorsSpawn.CFrame + Vector3.new(0,1,0))
    end
end

CoreEvent:FireAllClients("Round", "In Progress")
Countdown(RoundTime)
StartRound()

end

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
player.Team = Teams.Spectators
end)
end)

if not RoundStarted and #Players:GetPlayers() > 1 then
    StartRound()
end

end)

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
player.Team = Teams.Spectators
end)
end)
end)

local Players = game:GetService("Players");

local Teams = game:GetService("Teams");

local function AlivePlayers()
return #Teams.Survivors:GetPlayers();
end

local aliveCount = AlivePlayers();

if aliveCount <= 0 then
player.Team = Teams.Spectators
else
print(aliveCount.." players are still alive.");
end

#

@elder heath hear

#

thats for the server script

elder heath
#

paste the whole script in one message

elder heath
#

but you should only use that for short snippets. whole scripts -> upload as file. for simplicity.

#

like this

#

can you do that?

tight robin
#

nvm

elder heath
# tight robin

looks like you still have their code at the bottom, and 2 connections to game.players.playeradded for some reason?

tight robin
#

o

elder heath
#

show new code? just so we're starting from page one

tight robin
#

i think im lagging or smting cus it ceaps adding the code back

#

@elder heath

late pelicanBOT
#

studio** You are now Level 9! **studio

elder heath
# tight robin .
Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            player.Team = Teams.Spectators
        end)
    end)

    if not RoundStarted and #Players:GetPlayers() > 1 then
        StartRound()
    end
end)

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        humanoid.Died:Connect(function()
            player.Team = Teams.Spectators
        end)
    end)
end)``` what is this
tight robin
#

ether one of my atempts of fixing this or somthing elas i forgot

#

XX

#

@elder heath

elder heath
#

you'll need to sort that out before you can do anything else

tight robin
#

hi @elder heath

#

i did a youtoob how to code cors thing and i think ive lernt some of the basikes but

#

im still lerning

#

alto is is still not going perfictly smoothly

#

ii were i dident ven toch that scrip becus i was doing somthing in another and it stopt working

#

then i realisd iwas going to delat that anyway becus i did not want it

#

and now im stuck on watever this is but i will opfuly figer it out