How can I make a cash given on kill script? (That saves)

dude you guys still here the issue is so easy but your coding is just weird

Hey, it doesn’t have any errors in output, but it doesn’t really save quite properly, like, the cash only updates if I have changed the script significantly. I don’t know how to explain it quite well.

local conf = game.ReplicatedStorage:WaitForChild("Configuration")
local currencyName = conf:WaitForChild("CurrencyName")
local LoadData = require(game.ServerScriptService.ShopServer.ModuleScripts.LoadData)

local ShopServer = game.ServerScriptService:WaitForChild("ShopServer")
local SaveData = require(ShopServer.ModuleScripts:WaitForChild("SaveData"))

-- Function to give cash to the creator of the killed player and save data after each kill
local function OnPlayerDeath(character)
	local creatorTag = character.Humanoid:FindFirstChild("creator")
	if creatorTag and creatorTag.Value then
		local stats = creatorTag.Value:FindFirstChild("leaderstats")
		if stats then
			local cashStat = stats:FindFirstChild(currencyName.Value)
			if cashStat then
				cashStat.Value = cashStat.Value + 20 -- Reward the creator with 20 cash
				local player = game.Players:GetPlayerFromCharacter(character)
				if player then
					local success = SaveData(player) -- Save player data after each kill
					if success then
						print("Data saved successfully for player:", player.Name)
					else
						warn("Failed to save data for player:", player.Name)
					end
				end
			end
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	-- Listen for character added events
	player:WaitForChild("leaderstats")
	local loadedData = LoadData(player)
	if loadedData then
		player.leaderstats:WaitForChild(currencyName.Value).Value = loadedData.Cash or 0
	end
	player.CharacterAdded:Connect(function(character)
		-- Listen for player deaths
		character:WaitForChild("Humanoid").Died:Connect(function()
			OnPlayerDeath(character)
		end)
	end)
end)

Maybe I did something wrong here? I don’t really quite know…