Hi Nikkasfied. The answer below/above me works but that is not the only way to do so. There are numerous ways you can do it and I will show you 3 examples of the ones that work
To show you an example, I have 2 Bricks in Workspace, named ClickBrick and ChangeColour. When clicked on the ClickBrick it will result in printing, "Brick is Clicked". Then when clicked on the ChangeColour Brick, the brick will change into red colour.
- First One
local Workspace = game:GetService("Workspace")
local button = Workspace:WaitForChild("ClickBrick")
local ColourChanger = Workspace:WaitForChild("ChangeColour")
local function printButtonWhenClicked ()
print("It is clicked!")
ColourChanger.ClickDetector.MouseClick:Connect(function()
ColourChanger.BrickColor = BrickColor.Red()
print("Changed to red colour!")
end)
end
button.ClickDetector.MouseClick:Connect(printButtonWhenClicked)
- Second One
local Workspace = game:GetService("Workspace")
local button = Workspace:WaitForChild("ClickBrick")
local ColourChanger = Workspace:WaitForChild("ChangeColour")
button.ClickDetector.MouseClick:Connect(function()
print("It is clicked!")
ColourChanger.ClickDetector.MouseClick:Connect(function()
ColourChanger.BrickColor = BrickColor.Red()
print("Changed to red colour!")
end)
end)
- Third One
local Workspace = game:GetService("Workspace")
local button = Workspace:WaitForChild("ClickBrick")
local ColourChanger = Workspace:WaitForChild("ChangeColour")
changePartColour = function()
print("It is clicked!")
local function changeBrickColour ()
ColourChanger.BrickColor = BrickColor.Red()
print("Changed to red colour!")
end
ColourChanger.ClickDetector.MouseClick:Connect(changeBrickColour)
end
button.ClickDetector.MouseClick:Connect(changePartColour)
These are the only three examples I will show you. There are Methods and Tables too which you can apply similar concept.
I recommend checking out more on the wiki for information
####Anonymous Function
####Global Function
####Functions
Some other good posts in ScriptingHelpers as well
#####What are the Differences between "Local Function" and "Function"?
Have a lovely day of coding
2 comments
Line 5 on the second block should be: "script.Parent.Value.Changed:connect(OnValueChanged)"
On your first code, line 3, what is 'script.Parent.Value'?