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

Problems with NPC's sword not firing touched event on a anchored object?

Asked by 4 years ago

In my game i need an npc to destory a anchored object. For some reason this isnt working proper. The npc's sword fires the touched event once then it fires a random. Is there a way to fix this

Code:

Handle.Touched:Connect(function(Hit) -- This isnt firing when the npc touched a tycoon part
    local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
    if Humanoid and not Hit.Parent.Parent.Name == "Troops" then
        Humanoid:TakeDamage(script.Parent.Parent.TroopScripts.Damage.Value)
        script.Parent.CanAttack.Value = false
    end

    local StringValue = Hit.Parent:FindFirstChild("PName")
    if StringValue and string.find(Hit.Parent.Name, "Tycoon") and StringValue.Value ~= script.Parent.Parent.Name then
        Hit.Parent.Health.Value -= (script.Parent.Parent.TroopScripts.Damage.Value)
        script.Parent.CanAttack.Value = false
    end
end)
0
It fires a random what? LeedleLeeRocket 1257 — 4y
0
it fires randomly MikkelCircled 42 — 4y

Answer this question