I’ve been trying for the past few days to fix this bug but nothing really seems to work,
function endRound(winner)
print("End of round")
print(winner.Name .. " won the game!")
for i, plr in pairs(game.Players:GetChildren()) do
print("Updating")
updateKills:InvokeClient(plr, redPlayerKills, bluePlayerKills)
winGame:InvokeClient(winner.Name)
end
--get rid of all connections
warn(101)
for i, plr in pairs(game.Players:GetChildren()) do
clearPlayers:InvokeClient(plr)
warn(202)
plr.RespawnLocation = workspace.Start.SpawnLocation
if plr.Character:FindFirstChild("HumanoidRootPart") then
plr.Character.HumanoidRootPart.Position = workspace.Start.SpawnLocation.Position + Vector3.new(0,5,0)
end
plr.Team = game.Teams.Waiting
end
for i, connect in pairs (connections) do
connect:Disconnect()
end
wait(15)
print("Starting new round")
redPlayerKills = {}
bluePlayerKills = {}
--waiting till next round
roundHandler()
warn(303)
end
local maxKills = 41
local lastPlayer = nil
game.ReplicatedStorage.KillPlayer.OnInvoke = function<string>(player1 : string, playerKilled1 : string)
warn("test")
local player = game.Players:FindFirstChild(player1)
local playerKilled = game.Players:FindFirstChild(playerKilled1)
if lastPlayer ~= player then
lastPlayer = player
warn(player.Name .. " got a kill")
for i, plrStats in pairs(redPlayerKills) do
print(plrStats)
if plrStats[1] == player then
plrStats[2] += 1
print(plrStats[2])
if plrStats[2] >= maxKills then
endRound(player)
end
end
end
for i, plrStats in pairs(bluePlayerKills) do
if plrStats[1] == player then
plrStats[2] += 1
print(plrStats[2])
if plrStats[2] >= maxKills then
endRound(player)
end
end
end
warn("passed")
for i, plr in pairs(game.Players:GetChildren()) do
print("Updating1")
updateKills:InvokeClient(plr, redPlayerKills, bluePlayerKills)
end
coroutine.wrap(function()
wait(.25)
lastPlayer = nil
end)()
end
print("Killed")
game.ReplicatedStorage.KillFeed:FireAllClients(player.Name, playerKilled.Name)
end
The 41th time it is invoked with the same parameters, it just throws an error saying “Unable to cast value to Object”, when invoked it is always given 2 strings, the killer’s name and the victim’s name.
It throws the error after printing “Updating” once, therefore it stops after one iteration in the endRound function. Anything that can help fix this bug is appreciated!