I'm very new to coding and I've been recently testing things out. I wanted to make a brick where if you were to click it, another brick would change color. I've put the script into Workspace, not in the bricks.
Heres the script:
clickdetect = game.Workspace.MyPart.ClickDetector
clickdetect.MouseClick:Connect(function() game.Workspace.MyPart2.BrickColor = BrickColor.new("Navy Blue") end)
--MyPart is the brick you click --MyPart2 is the brick thats supposed to change color**
If you know how to fix it, please help me, thank you.
It actually works! But it needs to be in a local script, a local script only happens for you, unless you use a remote event or a remote function
Insert a Local Script In the StarterPlayerScripts in the StarterPlayer tab on your Explorer
Also do like this
game.Workspace.Part2.BrickColor = BrickColor.new("Navy blue")
That will change the brickcolor
then insert your script :)
local ClickDetector = game.Workspace.MyPart.ClickDetector ClickDetector.MouseClick:Connect(function() game.Workspace.Part2.BrickColor = BrickColor.new("Navy blue") end)
I know this has got nothing with your question to do but, there is something called a Remote Function
Remote functions basically makes a Local Script Visible to everyone.
"Whats the point of using a Remote Event when you can just do it in a Normal Script!"
Well, A script does not always work in a Normal Script, for example if we want to make your script visible to everyone, then it would not work in a normal script. So thats why we use Remote Events and why they are usefull
local ClickDetector = game.Workspace.MyPart.ClickDetector local RS = game:GetService("ReplicatedStorage") local RemoteFunction = RS:WaitForChild("RemoteFunction") local MyPart = ClickDetector.Parent ClickDetector.MouseClick:Connect(function() RemoteFunction:InvokeServer(MyPart) end)
Create a Normal script in the serverscript
local ClickDetector = game.Workspace.MyPart.ClickDetector local RS = game:GetService("ReplicatedStorage") local RemoteFunction = RS:WaitForChild("RemoteFunction") local MyPart = ClickDetector.Parent RemoteFunction.OnServerInvoke = function(player, MyPart) MyPart.BrickColor = BrickColor.new("Baby blue") end
If you are a beginner i don't recommend you to just jump into Remote-Functions. I was just teaching you ahead