I have been trying to make a tag that the server can read so it knows who killed who. I put my tag and untag functions into the remote event script so that when damage is dealt, the tag is also made. When the NPC dies, however, the console always returns the tag as nil. What am I doing wrong? I am desperate for help, I've tried figuring this out for days lol.
local debris = game:GetService("Debris")
local function tagHumanoid(hum, player)
local tag = Instance.new("ObjectValue", hum)
tag.Name = "creator"
tag.Value = player
debris:AddItem(tag, .5)
end
local function untagHumanoid(hum)
for i, v in pairs(hum: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)
This script is what tags, untags, and deals damage. I am almost certain this is where the tags need to be.
local hum = script.Parent.Humanoid
hum.Died:Connect(function()
local tag = hum:FindFirstChild("creator")
if tag then
local player = tag.Value
local Cash = player.leaderstats.Cash
Cash.Value = Cash.Value + 10
end
end)
This is the script inside the NPC. It should find my creator tag but it always returns nil if I put a print statement under FindFirstChild.

2 comments
So I can change Target to Target.Humanoid so it will parent to the humanoid rather than the model? I'm new to Lua, sorry.
That did the trick. Can't believe I never tried Target.Humanoid, I didn't know there was a difference. Thank you!!