Code:
game.Players.PlayerAdded:Connect(function(plr)
table.insert(PlrsPlaying,plr.Name)
plr.CharacterAdded:Connect(function(Char)
repeat task.wait() until Char:FindFirstChild("Humanoid")
Char.Humanoid.Died:Connect(function()
print(plr.Name .. " died")
end)
end)
end)
I want the player to be removed from the players playing table so they wont be awarded
1 Like
Please don’t do this, use :WaitForChild(), even though you are waiting for the character to load in the line above this. If you remove this line, does it run correctly?
1 Like
i actually tried with the waitforchild but it didnt work either
1 Like
Try this, in your snippet, you’re not defining playersPlaying, if it still doesn’t work, try giving us the output in the console:
local playersPlaying = {}
game.Players.PlayerAdded:Connect(function(player)
table.insert(playersPlaying, player.Name)
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
print(player.Name .. " died")
table.remove(playersPlaying, table.find(playersPlaying, player.Name))
end)
end)
end)
Also please don’t leave so much space, shortening your code makes it look much more organized.
i defined the table above also it gives no output
Is your script server-sided or client-sided?
I tried it and in my case it worked:
I printed the table when I joined and loaded and when I died.
I used the code I gave you earlier.
did you use the code above? that you showed me
Seems like you’re probably going in an infinite loop beacuse of the third line:
repeat task.wait() until #Plrs:GetPlayers() > 0
Try cancelling that line and see if you get output. (Put – in front of the line)
1 Like
its not a loop i just printed after that line and it printed what i told it to
1 Like
Full Code:
local Plrs = game:GetService("Players")
repeat task.wait() until #Plrs:GetPlayers() > 0
local LightSignal = workspace:WaitForChild("LightSignal")
local MinPlrs = 2
local UpdateStatus = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("UpdateStatus")
local PlrsPlaying = {}
Plrs.PlayerAdded:Connect(function(plr)
table.insert(PlrsPlaying,plr.Name)
plr.CharacterAdded:Connect(function(Char)
Char:WaitForChild("Humanoid").Died:Connect(function()
if table.find(PlrsPlaying,plr.Name) then
table.remove(PlrsPlaying,table.find(PlrsPlaying,plr.Name))
end
end)
end)
end)
Plrs.PlayerRemoving:Connect(function(plr)
if table.find(PlrsPlaying,plr.Name) then
table.remove(PlrsPlaying,table.find(PlrsPlaying,plr.Name))
end
end)
while true do
if #Plrs:GetPlayers() < MinPlrs then
local PlrsNeededToStart = MinPlrs - #Plrs:GetPlayers()
UpdateStatus:FireAllClients("Waiting for " .. PlrsNeededToStart .. " more players.")
else
for secs = 30,0,-1 do
UpdateStatus:FireAllClients("Intermission: " .. secs .. "s")
task.wait(1)
end
for _, plr in pairs(Plrs:GetPlayers()) do
table.insert(PlrsPlaying,plr.Name)
end
-- Start Game
end
task.wait(1)
end
What kind of script is it and where is it located?
You can try this!
game.Players.PlayerAdded:Connect(function(plr)
table.insert(PlrsPlaying, plr.Name)
plr.CharacterAdded:Connect(function(Char)
repeat task.wait() until Char:FindFirstChild("Humanoid")
Char.Humanoid.Died:Connect(function()
print(plr.Name .. " died")
for i, playerName in ipairs(PlrsPlaying) do
if playerName == plr.Name then
table.remove(PlrsPlaying, i)
break
end
end
end)
end)
end)
The script I gave him works just fine, I tested it and I’m sure yours and his works too, I think the reason for it not firing is beacuse of something not allowing the snippet to run. Maybe it’s stuck at a loop, or maybe it’s not where it’s supposed to be?
norm script and in serverscriptservice
So a server-sided script then?
Could be this causing an infinite loop, try cancelling this line
that could actually be it try removing it
Maybe he had a typo or it just doesn’t exist therefore causing a loop
Additionally, make sure the code is running in the correct execution context. If it’s intended to run on the server, confirm that it is running on the server and not on the client.