Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

2 comments

0

I'm not too sure but if the primarypart is the humanoidrootpart and such, would that detect collisions?

0

Idk if this is the problem but you forgot to close the parenthesis. The last end should say end) instead.

1 answer

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.

1 comment

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.