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

Why Won't My Fireball Harm NPCs?

Asked by 4 years ago

I'm working on a game that basically allows you to have superpowers, and the first power I'm creating is a fireball launcher. Whenever you click somewhere, a fireball mesh is sent to the location through a tween (the easingstyle is Enum.EasingStyle.Linear so it's going straight to the point). The fireball is supposed to hurt things it touches if it has a Humanoid (to hurt players/NPCs). However, this fireball is not hurting some default Dummy NPCs I put into the game; I did not remove/change anything inside the Dummies, other than moving them around the map to better locations.

Here's the script I have inside the Fireball mesh that's supposed to detect when it's touching something:

script.Parent.Touched:Connect(function(part)
    print("Part was touched, Parent name is "..part.Parent.Name)
    local parent = part.Parent
    local humanoid = parent:FindFirstChild("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(parent)
        if not (script.Parent.Parent.Owner.Value == player) then -- All this does is make it where the person throwing the fireball doesn't get hurt
            humanoid.Health = parent.Humanoid.Health - 30
        end
    end
end)

Whenever I use the fireball and throw it at an NPC, it doesn't even print "Part was touched blah blah blah", which means it didn't even detect it hitting the NPC. How would I fix this?

Thanks for trying to help, I appreciate it

0
try switching it up, put the detect damage script inside the ncp BradNewTypical 232 — 4y
0
What kind of script are you using? Because i was able to get it to work by editing the code a little bit. preston1196 82 — 4y
0
I fixed it. The NPCs were partly anchored for some reason lol. My bad. User#28017 0 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I was able to get it to work by deleting the owner function.

script.Parent.Touched:Connect(function(part)
    print("Part was touched, Parent name is "..part.Parent.Name)
    local parent = part.Parent
    local humanoid = parent:FindFirstChild("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(parent)
        if not (script.Parent.Parent == player) then -- All this does is make it where the person throwing the fireball doesn't get hurt
            humanoid.Health = parent.Humanoid.Health - 30
        end
    end
end)
Ad
Log in to vote
0
Answered by 4 years ago

Bruhhhh. Ok, so the problem was that the NPCs were anchored lol. Sorry, the NPC's props never crossed my mind.

Answer this question