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

How to detect if a npc touched a part?

Asked by 4 years ago
Edited 4 years ago

I can't seem to figure out how to detect if a certain npc touched a part and then send a message (Not a player) Please Help! (Can't Use Discord)

1 answer

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

you can try this Add a remote event called "NPCPrint" or whatever you would like to the replicatedstorage.

game.Workspace.Part.Touched:Connect(function(Hit) --Event touch
if Hit.Parent.Name = "MyNPC" then --Check if the one who touched is the npc
print("MyNPC touched my párt") --Send a message that the npc has touched the part
game.ReplicatedStorage.NPCPrint:FireAllClients() --The server fires the remote event to all players on the server
script.Disabled = true
--Type the following two lines if you want the event to happen again
wait(10)
script.Disabled = false
end
end)

Then, go to StarterPlayer > StarterPlayerScripts. In there, add a LocalScript, type the following:

game.ReplicatedStorage.NPCPrint.OnClientEvent:Connect(function()
      game.StarterGui:SetCore("ChatMakeSystemMessage", { --It will add a server message to all players with the following proterties:
      Text = "The NPC has touched the part!" --Or change to whatever text the message will display
      Color = Color3.fromRGB(0,0,0) --Or change to another color you would like
      Font = Enum.Font.GothamBold --Or other font
      TextSize = 18 --Or other size
      })
end)

I think we are done! Hope it helps.

0
Do i correct the = "MyNPC" to == "MyNPC"? Agent0fChaos0 14 — 4y
0
Nevermind Got it working Agent0fChaos0 14 — 4y
0
How do I make it so that it will only run once because when it touches it now it will log it mutiple times Agent0fChaos0 14 — 4y
0
And how would i make it send a message in chat Agent0fChaos0 14 — 4y
0
Let me try to do it yuni_Boy1234 320 — 4y
Ad

Answer this question