Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help me figure out why npc kills with my custom sword does not reward exp or money?

Asked by 5 years ago

So, I made a custom sword which swings and does damage but, the problem is, it does not reward the player exp or money (denarii). I used the classic sword from the toolbox and it works fine so I don't see the problem.

Here is the sword damage script

local tool = script.Parent
debounce = false
tool.Activated:Connect(function()
    if debounce == false then
        debounce = true
        local dmg = script.Damage:Clone()
        dmg.Parent = script.Parent.Handle
        dmg.Disabled = false
        wait(.5)
        debounce = false
        if dmg then
            dmg:Destroy()
        end
    end
end)

(this next script is inside of the previous script)

local weapon = script.Parent
local dmg = 20 -- Damage

weapon.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") then -- Change "Enemy" to the humanoid you want to be killable
        local humanoid = part.Parent:FindFirstChild("Humanoid") -- Change the "Enemy" Again
        humanoid:TakeDamage(dmg)
        script:Destroy()
    end
end)

Here is the reward script, it is placed inside of the enemy npc

local Humanoid = script.Parent.Humanoid -- User choice
function PwntX_X() 
local tag = Humanoid:findFirstChild("creator") 
    if tag ~= nil then 
        if tag.Value ~= nil then 
local Leaderstats = tag.Value:findFirstChild("leaderstats") 
            if Leaderstats ~= nil then 
Leaderstats.Denarii.Value = Leaderstats.Denarii.Value + math.random(1,5)
Leaderstats.Exp.Value = Leaderstats.Exp.Value + math.random(1,5)
wait(0.1)
script:remove()
            end 
        end 
    end 
end 
Humanoid.Died:connect(PwntX_X) 
0
try using FindFirstChild and Connect instead of findFirstChild and connect in third script Lazarix9 245 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

regardless what you try to do in 2nd or 3rd script,

why do you destroy the dmg script as soon as you created it?

        if dmg then 
             dmg:Destroy() 
         end 



Ad

Answer this question