#help with function repeating itself?

18 messages · Page 1 of 1 (latest)

agile kestrel
#

e

#

u forgot disconnecting

#
local function DeathCounter(player: Player)
    local characterAddedConnection
    local humanoidDiedConnection

    local function onHumanoidDied()
        if player.Team.Name == "TeamA" then
            av.Value += 1
            print(player.Name .. " has died team death total is  " .. av.Value .. " deaths.")
            remoteEvent:FireAllClients(true,av.Value,bv.Value)
        elseif player.Team.Name == "TeamB" then
            bv.Value += 1
            print(player.Name .. " has died team death total is  " .. bv.Value .. " deaths.")
            remoteEvent:FireAllClients(true,av.Value,bv.Value)
        end
    end

    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:WaitForChild("Humanoid")
    if humanoidDiedConnection then
        humanoidDiedConnection:Disconnect()
    end
    humanoidDiedConnection = humanoid.Died:Connect(onHumanoidDied)
    characterAddedConnection = player.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")
        if humanoidDiedConnection then
            humanoidDiedConnection:Disconnect()
        end
        humanoidDiedConnection = humanoid.Died:Connect(onHumanoidDied)
    end)
end
#

O really?

#

Mhm

#
local function DeathCounter(player: Player)
    local characterAddedConnection
    local humanoidDiedConnection
    --print("Player object:", player.Name)
    --local WAY = workspace:FindFirstChild("waypoint")
    
    local function onHumanoidDied()
        --WAY:Destroy()
        if player.Team.Name == "TeamA" then
            av.Value += 1
            print(player.Name .. " has died. Team death total is " .. av.Value .. " deaths.")
            remoteEvent:FireAllClients(true, av.Value, bv.Value)
        elseif player.Team.Name == "TeamB" then
            bv.Value += 1
            print(player.Name .. " has died. Team death total is " .. bv.Value .. " deaths.")
            remoteEvent:FireAllClients(true, av.Value, bv.Value)
        end
    end
    
    local function connectDeathEvent()
        local character = player.Character or player.CharacterAdded:Wait()
        local humanoid = character:WaitForChild("Humanoid")
        humanoidDiedConnection = humanoid.Died:Connect(onHumanoidDied)
    end
    
    characterAddedConnection = player.CharacterAdded:Connect(function(char)
        humanoidDiedConnection:Disconnect()
        connectDeathEvent()
    end)
    
    connectDeathEvent()
end

while x do
    if InRound.Value == true and CHOSEN_GAMEMODE.Value == "PRIS" then
        print("started deathmatch")
        x = false
        timerActive = true
        if not TeamA or not TeamB then
            TeamA = Instance.new("Team")
            TeamA.Name = "TeamA"
            TeamA.TeamColor = BrickColor.new("Really red")
            TeamA.Parent = game:GetService("Teams")

            TeamB = Instance.new("Team")
            TeamB.Name = "TeamB"
            TeamB.TeamColor = BrickColor.new("Really blue")
            TeamB.Parent = game:GetService("Teams")

            for i, player in ipairs(players:GetPlayers()) do
                DeathCounter(player)
            end
        end
    end
end
#

try

#

tell me if it works

west cargo
#
local function DeathCounter(player: Player)
    local function onHumanoidDied()
        if player.Team.Name == "TeamA" then
            av.Value += 1
            remoteEvent:FireAllClients(true, av.Value, bv.Value)
        elseif player.Team.Name == "TeamB" then
            bv.Value += 1
            remoteEvent:FireAllClients(true, av.Value, bv.Value)
        end
    end

    local function onCharacterAdded(char)
        local humanoid = char:WaitForChild("Humanoid")
        humanoid.Died:Connect(onHumanoidDied)
    end

    player.CharacterAdded:Connect(onCharacterAdded)
    if player.Character then
        onCharacterAdded(player.Character)
    end
end
#

still getting the error?

agile kestrel
#

?

west cargo
#

ik

#

but I mean error as it doesn't work as you wishes it to

#

i don't see the function of the death counter counting it wrong

#

try testing it alone

#

like, without the loop thing

#

okk

#

ye