Award players with leaderstat when character/boss dies

I’m trying to make it so when a boss in the workspace named “normalDETRIMENT” dies each player gets awarded 200 Lunar Coins. (i.e. lunar coins are part of a leaderstat which is [“Lunar Coins”]) I made a script to do this… but it doesn’t do anything. Nothing is printed in the console or returned when the boss dies. Here is the script I made

local function awardLunarCoins(player)
	local leaderstats = player:WaitForChild("leaderstats")
	local lunarCoins = leaderstats:FindFirstChild("LunarCoins")

	if lunarCoins then
		lunarCoins.Value = lunarCoins.Value + 200
	end
end

local function onCharacterDied(character)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid and humanoid.Health <= 0 and character.Name == "normalDETRIMENT" then
		for _, player in ipairs(game.Players:GetPlayers()) do
			awardLunarCoins(player)
		end
	end
end

I’m wondering what’s causing this to not work, and I still haven’t found any ideas of which they make it stop working

1 Like

I’d start by adding outputs into each subroutine to check if and when they are running.

That would help to narrow down where the issue is coming from much more easily.

1 Like

sorry, i just revised the script and fixed the error myself. again, apologies for making this when i just fixed it myself.

1 Like

No worries, glad you fixed it!

1 Like