So, I want to make a script when the player touches a brick it says something in chat.
It's quite easy to do. So first you make remote event in Replicated Storage. You can make script in brick you want people to touch and put this in it:
1 | local event = game.ReplicatedStorage.BrickTouchChatEvent -- location to the remote event |
2 | script.Parent.Touched:Connect( function (hit) -- touched function |
3 | if hit.Parent:FindFirstChild "Humanoid" then -- checks if its human |
4 | event:FireAllClients() -- fires event |
5 | end |
6 | end ) |
What it does is that it fires event to all clients. To receive it you put local script into StarterPlayerScripts:
1 | local event = game.ReplicatedStorage.BrickTouchChatEvent |
2 | event.OnClientEvent:Connect( function () -- receives the event |
3 | game.StarterGui:SetCore( "ChatMakeSystemMessage" , { |
4 | Text = "Someone has touched da bricc!" , -- text that it will say |
5 | Color = Color 3. fromRGB( 255 , 0 , 255 ) -- Set any color you want |
6 | } ) |
7 | end ) |
There is no debounce but i think you can figure it out how to make that. Hope it helps.
Here Look Make A Local Script And Place The Local Script In StarterPlayer.StarterPlayerScripts Heres the Script It Make Sure You Read The Green Coloured Text! script:
01 | local debounce = false |
02 |
03 | local bc = BrickColor.new( "Really blue" ) |
04 | local part = game.Workspace.Part --refrence the part you want to be hit! |
05 | part.Touched:Connect( function (hit) |
06 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
07 | if debounce = = false then |
08 | debounce = true |
09 | print ( "Humanoid Touched Brick!" ) |
10 | game.StarterGui:SetCore( "ChatMakeSystemMessage" , { |
11 | Text = "You Just Touched The Sacred Brick D:" ; --Here You Can Change The Text To Whatever You Like! |
12 | Font = Enum.Font.Cartoon; |
13 | Color = bc.Color; |
14 | FontSize = Enum.FontSize.Size 18 ; |
15 | } ) |