So ive made a custom weapon, and i need it to work for my xp giver on killing an npc.
but i couldnt really find any methods and neither do i understand how creator tags work that much…
So here i am.
Here are the scripts included:
Swing script:
local tool = script.Parent
local cooldown = script.Cooldown.Value
local animation = script:WaitForChild("Animation")
tool.Activated:Connect(function()
local humanoid = tool.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and cooldown == false then
cooldown = true
local playanim = humanoid:LoadAnimation(animation)
playanim:Play()
script.SlashSound:Play()
tool.Handle.Damage.Disabled = false
wait(2)
playanim:Stop()
tool.Handle.Damage.Disabled = true
wait(0.5)
cooldown = false
end
end)
Damage script:
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
script.HitSound:Play()
humanoid:TakeDamage(5)
end
end)
Reward script:
local Humanoid = script.Parent.Humanoid
function Reward()
local tag = Humanoid:findFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local Data = tag.Value:findFirstChild("Data")
if Data ~= nil then
Data.Exp.Value = Data.Exp.Value + 100
wait(0.1)
script:remove()
end
end
end
end
Humanoid.Died:connect(Reward)