ChildAdded not working on humanoid?

So, I’ve been trying to do a combat logging system by checking for tags in the humanoid on the server (they are created by the server when a weapon does damage). But, I’ve been stumped for hours because this doesn’t seem to detect when the tags are added even though the creator tag is in the humanoid and is added.

local players = game:GetService("Players")

local rs = game:GetService("RunService")
local logEvent = game.ServerScriptService.Scripts.Stats.StatRequests.combatLog

local wait = function(t)
	t = t or rs.Heartbeat:Wait()
	
	local now = tick()
	repeat rs.Heartbeat:Wait() until tick() - now >= t
end

local combatLog = {}

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(function(char)
		local humanoid = char:WaitForChild("Humanoid")
		
		humanoid.ChildAdded:Connect(function(child)
			if combatLog[player.Name] then return end 
			
			if child:IsA("ObjectValue") and child.Name == "creator" then 
				print("Logged")
				combatLog[player.Name] = true 
				
				wait(10)
				
				repeat 
					if humanoid:FindFirstChild("creator") then 
						wait(10)
					else
						combatLog[player.Name] = false
					end					
				until not combatLog[player.Name]
			end
		end)
		
		humanoid.Died:Connect(function()
			if combatLog[player.Name] then
				combatLog[player.Name] = false
			end
		end)
	end)	
end

players.PlayerAdded:Connect(onPlayerAdded)

for _, player in ipairs(game.Players:GetPlayers()) do
	coroutine.wrap(onPlayerAdded)(player)
end

players.PlayerRemoving:Connect(function(player)
	combatLog:Fire(combatLog[player.Name])
	
	if combatLog[player.Name] then 
		combatLog[player.Name] = nil
	end
end)

Does ChildAdded not work in this situation or something?

Is the tag stored in the client or the server? If the tag is created via the client, you cannot access it from the server.

Yes:

I’ve fixed my problem though, I just accomplished what I wanted a different way so I guess I’ll close this

What did you do? I’m curious, how did you change it so it would work?

I just stopped using ChildAddeds/DescendantAddeds completely because they weren’t working for some reason, they werent picking up tags being created in the humanoid. So, all I did was just make a “Combat Log” folder on the server, and whenever a player took damage (which is when I tag usually), I just made a new function to add a new “Combat Log” tag of the player (if hit by another player) inside of the Combat Log folder for a longer time than the normal tags (Normal tags I only do like 4 seconds so that a kill isn’t detected long after you do damage to someone and they die, but I use 15 with the combat log tags). Debris is convenient to add them and automatically clean them up after the 15 seconds. From there it’s pretty easy; if a player leaves, I just check if they have a tag in the Combat Log folder, and if they do, I remove all of their weapons (guns, melee, utility) from their inventory before saving it. Then, when they come back into the game, their weapons are gone. Really I’d prefer to do this using tables since they are cleaner, hence why I was trying to use Child and DescendantAdded, but they weren’t working, and although this method may be “messier” (it’s really not), it works perfectly.

Edit: Here’s some code to better help you understand:

local function combatLog(humanoid)
	
	local old = game.ServerScriptService.CombatLog:FindFirstChild(humanoid.Parent.Name)
	
	if old then
		old:Destroy()
	end
	
	local combat = Instance.new("StringValue")
	combat.Name = humanoid.Parent.Name 
	combat.Parent = game.ServerScriptService.CombatLog
	debris:AddItem(combat, 15)
end
1 Like