I am trying to track the kills in my game to reward players with money but I can't get the creator tag to print an actual tag, it's always nil. I made my own weapon with a copied tag and untag method from a roblox sword. I put it in the dealdamage server script. What am I doing wrong?
function TagHumanoid(humanoid, player) local Creator_Tag = Instance.new("ObjectValue") Creator_Tag.Name = "creator" Creator_Tag.Value = player game:GetService("Debris"):AddItem(Creator_Tag, 2) Creator_Tag.Parent = humanoid end function UntagHumanoid(humanoid) for i, v in pairs(humanoid:GetChildren()) do if v:IsA("ObjectValue") and v.Name == "creator" then v:Destroy() end end end script.Parent.DealDamage.OnServerEvent:Connect(function(player, Target, Damage) UntagHumanoid(Target) TagHumanoid(Target, player) Target.Humanoid:TakeDamage(Damage) end) game.Players.PlayerAdded:Connect(TagHumanoid) game.Players.PlayerAdded:Connect(UntagHumanoid)
this is the damage script above.
local char = script.Parent local hum = char:WaitForChild("Humanoid") hum.Died:Connect(function() local tag = hum:FindFirstChild("creator") print(tag) if tag then local player = tag.Value local Cash = player.leaderstats.Cash Cash.Value = Cash.Value + 10 end end)
this is the server script inside the NPC I am testing with.
Again, the console always prints the tag as nil. Any help would be massively appreciated!