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

How to send a message after touching a item?

How would i make it so when it touches it sends a message from system in the chat box

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
end
end)

1 answer

✓ Accepted answer

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.

2 comments

0

Now it gives me the error in the local script: Error:(4,3) Expected '}' (to close '{' at line 2), got 'color'

0

i did some editing and now it works thank you

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