For some reason my code is working in studio but not in-game. I've been stumped on this for awhile now. The sword is supposed to tag a mob, then when the mob dies it awards the player with gold. But it doesnt work in-game
Heres the sword code; `
local tool = script.Parent
local handle = tool.Union
local cooldown = 0.45
local plr = game.Players.LocalPlayer
tool.Activated:Connect(function()
if swinging then return end
swinging = true
wait(cooldown)
if swinging then
swinging = false
end
end)
handle.Touched:Connect(function(hit)
if swinging then
swinging = false
print("hit")
local humanoid = hit.Parent:FindFirstChild('Enemy')
if not humanoid then return end
local tag = Instance.new('ObjectValue',humanoid)
tag.Name = 'creator'
tag.Value = plr
humanoid:TakeDamage(12)
wait(0.45)
tag:Destroy()
end
end)`
Heres the reward code: `
local reward = 5
local npc = script.Parent
local human = npc.Enemy
human.Died:Connect(function()
local tag = script.Parent.Enemy:FindFirstChild('creator')
local killer = tag.Value
killer.Data.Stats.Gold.Value = killer.Data.Stats.Gold.Value + reward
end)

5 comments
Heres the error it outputs http://prntscr.com/n04y5b
It's likely because "creator" doesn't exist. FindFirstChild() returns nil if the Instance does not exist in the directory FindFirstChild() is being called in.
Yeah, I figured. Any idea on how to fix this though?
Relocate creator to be a child of Enemy if it already isn't a child of Enemy.
The creator tag's parent is being set to the enemy. It's just not working in-game.