#how make script if all players are dead - play a sound

27 messages · Page 1 of 1 (latest)

rose moon
#
(PlayerDyingEvent)
  local alive = 0
  for _, player in PlayerService:GetPlayers() do
    if not player.Character then continue end
    if not player.Character: FindFirstChild("Humanoid") then continue end
    if player.Character.Humanoid.Health <= 0 then continue end
    alive += 1
  end
  if alive == 0 then
    sound:Play()
  end
end
rose moon
#

I made a typo

#

Wait

rose moon
#

Basically when a player dies, you check for all player's character in the game

#

If there is none, you can just play the sound

quaint haven
#

yea that code should work

#

but you didnt tell him to actually make that player death event

rose moon
narrow skiff
#

local PlayerService = game:GetService("Players")
local alive = 0
local sound = game.Workspace.Sound
for _, player in PlayerService:GetPlayers() do
if not player.Character then continue end
alive += 1
end
if alive == 0 then
sound:Play()
end

quaint haven
#

bo.

#

n.o

#

no.

#

so

#

first of all

#

you need to detect when a player dies

#

for that, i suggest connecting humanoid.Died in player.added and character.added

#

after that call the function that he made

rose moon
#

He can search for the event

#

I spoon-feed almost all of the sc

quaint haven
#

well, not like these kids will follow your instructions

#

few do so

rose moon
#

Haha ure right

narrow skiff
#

local sound= game workspace.sound local players = game.Players if players.Localplayer.Character.Humanoid.Health == 0 then sound:Play()?

quaint haven
#

ok

#

this is a different level