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

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

Asked by 4 years ago
Edited 4 years ago

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.

0
local script goodadmins 111 — 4y
0
:clap: :clap: Creacoz 210 — 4y

2 answers

Log in to vote
0
Answered by
Creacoz 210 Moderation Voter
4 years ago
Edited 4 years ago

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)

0
The Other player can still see that the part is red EnchMusic 26 — 4y
0
Oops sorry I forgot to check if it was the players name. I will change my answer Creacoz 210 — 4y
0
Thank you so much!!! It really worked! EnchMusic 26 — 4y
0
one question,can you make it so that the script is inside the part but not in Starter Player scripts? EnchMusic 26 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)

Answer this question