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

How do I see if an NPC is touching a certain model (Building)?

Asked by 3 years ago
Edited 3 years ago

I need to know how I can get my NPCs to see if they are touching the objective building in my game. I attempted a script that looks like this

Building = game.Workspace.BlueBuilding1
model = script.Parent



model.PrimaryPart.Touched:Connect(function(hit)
    if hit.Parent.Name == "BlueBuilding1" then
        print("got it")
        Building.Strength = Building.Strength - 100
        script.Parent.Humanoid.Health = 0
    end

    end

but it doesn't seem to be working.

0
I'm not too sure but if the primarypart is the humanoidrootpart and such, would that detect collisions? RedCoatOracuda 35 — 3y
0
Idk if this is the problem but you forgot to close the parenthesis. The last end should say end) instead. Bob4koolest 78 — 3y

1 answer

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

Small mistakes. You don't need primary part. This should do it:

Building = game.Workspace.BlueBuilding1
model = script.Parent

model.Touched:Connect(function(hit)
    if hit.Parent.Name == "BlueBuilding1" then
    print("got it")
    Building.Strength = Building.Strength - 100
        script.Parent.Humanoid.Health = 0
    end
end)

I didn't try this myself but it will probably work.

0
I tried it and it didn't work (nothing from output saying it was touched). Is it maybe because the model is a humanoid? (NPC) sicknoobie 0 — 3y
Ad

Answer this question