Hello, Ive been trying to make it so that after killing an NPC, the player earns money.
I have followed multiple tutorials and guides, but still dont unterstand how to script it… I need help on how to make the “creator tag” work.
These are the scripts I currently have;
In the NPC:
local Humanoid = script.Parent.Humanoid
function Dead()
local tag = Humanoid:FindFirstChild("creator")
if tag ~= nil then
local leaderstats = tag.Value:FindFirstChild("leaderstats")
if leaderstats ~= nil then
leaderstats.Cash.Value = leaderstats.Cash.Value +10
wait(0,1)
script:Remove()
end
end
end
Humanoid.Died:Connect(Dead)
In the sword:
local tool = script.Parent
local canDamage = false
local canSwing = true
local function onTouch(partOther)
local humanOther = partOther.Parent:FindFirstChild("Humanoid")
if not humanOther then return end
if humanOther.Parent == tool then return end
if humanOther.Parent ~= tool.Parent and canDamage then
humanOther:TakeDamage(50)
else
return
end
canDamage = false
end
local function slash()
if canSwing then
canSwing = false
local str = Instance.new("StringValue")
str.Name = "toolanim"
str.Value = "Slash"
str.Parent = tool
canDamage = true
wait(0.5)
canSwing = true
end
end
tool.Activated:Connect(slash)
tool.Handle.Touched:Connect(onTouch)