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?
Pls Help me because I am a beginner at scripting.
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)
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)