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

Why is the Touched event not functioning properly with NPCs?

Asked by 5 years ago

I tried debugging the script by adding prints, but it only printed the touched part's name, after that nothing happens. I have tried to direct the fireball's direction to an NPC, and none of the NPC's body parts' name is showing on the Developer Console of the Server tab.

The script below is in a Script

Oh yeah, it also prints other part's name, like the Baseplate for an example.

wait(1)

local fireball = script.Parent

repeat wait() until fireball:IsA("BasePart")

local Damage = script:WaitForChild("Damage")
local Creator = script:WaitForChild("Creator")

local player = Creator.Value
local pvp = player:WaitForChild("PvP")

local enabled = true

fireball.Touched:Connect(function(hit)
    if not enabled then return end

    print(script.Name..": "..hit.Name.." found!")
    fireball.Anchored = true

    if hit.Parent:FindFirstChild("Humanoid") then
        enabled = false

        local targetHumanoid = hit.Parent:FindFirstChild("Humanoid")
        if targetHumanoid ~= nil then
            print(script.Name..": Humanoid is dere")
            if game.Players:GetPlayerFromCharacter(targetHumanoid.Parent) then
                print(script.Name..": Target is a player.")
                local targetPlayer = game.Players:GetPlayerFromCharacter(targetHumanoid.Parent)
                local targetPvp = targetPlayer:WaitForChild("PvP")
                if pvp.Value and targetPvp.Value then
                    print(script.Name..": Both PvP on")
                    targetHumanoid:TakeDamage(Damage.Value)
                    print(script.Name..": Damaged inflicted")
                end
            else
                print(script.Name..": Target is an NPC")
                targetHumanoid:TakeDamage(Damage.Value)
                print(script.Name..": Damage inflicted")
            end
        end
    end

    wait(1.5)
    enabled = true
end)
0
Why do you have line 5 User#19524 175 — 5y
0
oh, it's because the DamageScript is within another script where that script will clone the DamageScript and put it into the fireball. The repeat loop is just to make sure the fireball is there, double check xd. CounterBoy123 53 — 5y
0
Line 5 would end instantly . User#19524 175 — 5y
0
yea lol CounterBoy123 53 — 5y

Answer this question