Infinite Yield Possible

I’m making a remake of Classic: Rocket Arena, and I’m almost done after the kills/deaths leaderboard update, but there’s 1 problem.

This problem is that when you fall on a killbrick, you die, obviously. But the killbrick’s kill doesn’t actually count as a death.

My kill/death leaderboard is scaled for rocket launcher kills, so I tried adding a function that checks when you die, and then award you a death, but that doesn’t work, and only makes the death count stop as a whole.

Here’s my code as a reference:

local function addBoard(player)
	local board = Instance.new("Folder", player)
	board.Name = "leaderstats"
	local kills = Instance.new("IntValue", board)
	kills.Name = "KOs"
	
	local deaths = Instance.new("IntValue", board)
	deaths.Name = "WOs"
end

game.Players.PlayerAdded:Connect(function(player)
	addBoard(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		hum.Died:Connect(function(plr)
			plr.leaderstats.WOs.Value += 1
			local tag = hum:FindFirstChild("creator")
			if tag and tag.Value then
				local ePlayer = tag.Value
				ePlayer.leaderstats.KOs.Value += 1
			end
		end)
	end)
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Where is the infinite yield occurring?

1 Like

oh, i forgot to say that. it happens at “plr.leaderstats.WOs.Value += 1”, where it can’t find leaderstats in plr.

Is it giving you an infinite yield or an error? Infinite yield only happens when you’re using WaitForChild, using period indexing shouldn’t give you this

1 Like

i’m thinking it was most likely an error, i probably mixed it up with an infinite yield because of all the errors that constantly happen in my game (i removed every animation except the idle animation)

Oh I just realized, humanoid.Died doesn’t pass any args to the connected function, so plr would be nil in that case. I think you should be using player instead of plr. You should be able to remove plr and all references to it altogether in favour of player

1 Like

i think that was my problem. thank you for helping me!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.