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

How can I make a Local OnTouch Part? (or something like that)

How do I make an OnTouch script where it only happens on the players view that touched the part?

for example,The player touched the part and then it turned red on its screen and then, on the other player's screen it needs to be green not red.

Maybe like this?

  1. script.Parent.Touched:Connect(function()
  2. script.Parent.BrickColor = BrickColor.new("Bright red")
  3. end)
  4. script.Parent.TouchEnded:Connect(function()
  5. wait(0) --does nothing
  6. end)

Pls Help me because I am a beginner at scripting.

2 comments

0

local script

0

:clap: :clap:

2 answers

✓ Accepted answer

Try this and tell me if it works. (I put it in the StarterPlayerScripts)

Everything in this is in a local script

local part = game:GetService("Workspace").Whateveryouwant

part.Touched:Connect(function(hit)
	if hit.Parent.Name == game.Players.LocalPlayer.Name then --Checks if the local player touched!
  	  part.BrickColor = BrickColor.new("Bright red")
	end
end)

(Change the "Whateveryouwant" by the way)

4 comments

0

The Other player can still see that the part is red

0

Oops sorry I forgot to check if it was the players name. I will change my answer

0

Thank you so much!!! It really worked!

0

one question,can you make it so that the script is inside the part but not in Starter Player scripts?

Hello, EnchMusic;

All you have to do is to use a LocalScript,

since LocalScripts won't work unless if they are inside a Player's Backpack or PlayerGui,

you can't place it inside a part in Workspace, there are two possible solutions to fix this problem,

First : Defining your part in Workspace.

Second : Using RemoteEvents.

Since the First method is the easiest one i'm only going to help you with that.

Simply make a LocalScript inside the StarterPack ( or StarterGui ) folder, and paste the script below inside ( note : You have to define your part in "YourPart" variable! )

local YourPart = workspace.Part -- Change " Part " to the name of your Part inside Workspace 

YourPart.Touched:Connect(function()
YourPart.BrickColor = BrickColor.new("Bright red")
end)

YourPart.TouchEnded:Connect(function()
YourPart.BrickColor = BrickColor.new("Forest green") -- Rmove this if you want.
end)

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