So i wanna make like when player kills an npc it will get rewards but the code below doesnt work.
I’m also new to collection service
local CollectionService = game:GetService("CollectionService")
local TagPart = CollectionService:GetTagged("NPCRewards")
local humanoid = script.Parent:WaitForChild("Humanoid")
function Died()
game.ServerStorage.GiveExp:Fire(50, humanoid:FindFirstChild("creator").Value)
wait(0.1)
local tag = humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Coins = tag.Value:FindFirstChild("Money")
local Exp = tag.Value:FindFirstChild("Exp")
if Coins ~= nil then
Coins.Value = Coins.Value + 10
end
if Exp ~= nil then
Exp.Value = Exp.Value + 10
end
end
end
script.Parent:Destroy()
end
for _, TagParts in pairs(TagPart) do
humanoid.Died:Connect(Died)
Died(TagParts)
end
Also here’s the error