Code not working properly

It is PD system for AOT game. Problem is that it shows the player who started an event, dead. Can someone help me?



1 Like

Could you please put your code in code blocks?

--like this

It makes it easier to read, And you can display the full code.

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")

local PDAdmins = require(ReplicatedStorage.PDAdmins)

local PD = false

local Alive = {}
local Dead = {}

local globalDebounce = false
local globalDebounceTimer = 10

Remotes.InitPD.OnServerEvent:Connect(function(player: Player, state: boolean)
    if not globalDebounce then
        if state then
            if table.find(PDAdmins, player.UserId) and not PD then
                globalDebounce = true
                PD = true
                print(player.Name.. " Is Whitelisted!")

                Remotes.PDClient:FireAllClients(true, true)

                Alive = Players:GetPlayers()
                print(Alive)

                task.delay(globalDebounceTimer, function()
                    globalDebounce = false
                end)
            end
        else
            if table.find(PDAdmins, player.UserId) and PD then
                globalDebounce = true
                PD = false
                print(player.Name.. " Is Whitelisted!")

                Remotes.PDClient:FireAllClients(false, false)
                Remotes.InitPD:FireAllClients(nil, true)

                Alive = {}
                Dead = {}

                task.delay(globalDebounceTimer, function()
                    globalDebounce = false
                end)
            end
        end
    end
end)

Remotes.PlayerDied.OnServerEvent:Connect(function(player: Player)
    if PD then
        if table.find(Alive, player) then
            table.remove(Alive, table.find(Alive, player))
            table.insert(Dead, player)
            Remotes.InitPD:FireAllClients(player, false)
        end
    end
end)

Players.PlayerAdded:Connect(function(player)
    if table.find(PDAdmins, player.UserId) and PD then
        if #Alive > 0 then
            for _, aliveplayer in pairs(Alive) do
                local newplayer = player:WaitForChild("PlayerGui"):WaitForChild("PD").PDFrame.MainFrame.Alive.Template:Clone()
                newplayer.Text = aliveplayer.Name
                newplayer.Name = aliveplayer.Name
                newplayer.Visible = true
                newplayer.Parent = player:WaitForChild("PlayerGui"):WaitForChild("PD").PDFrame.MainFrame.Alive
            end
        end
        
        if #Dead > 0 then
            for _, deadplayer in pairs(Dead) do
                local newplayer = player:WaitForChild("PlayerGui"):WaitForChild("PD").PDFrame.MainFrame.Dead.Template:Clone()
                newplayer.Text = deadplayer.Name
                newplayer.Name = deadplayer.Name
                newplayer.Visible = true
                newplayer.Parent = player:WaitForChild("PlayerGui"):WaitForChild("PD").PDFrame.MainFrame.Dead
            end
        end
    end
end)

Have you checked the output?
You can see the errors in the output then fix it, That is how i usually fix my code
If i can not fix it, I search the devforum, If that is no help, I make a topic.
Try looking the error in the output

Im not home, but my guy told me there are no errors from this code

What? Can you rephrase your problem? I have no idea what you mean.

1 Like

So, after a person starts an event (PD), they are listed as dead, which confuses us