I need help making a client script that enables a ColorCorrection effect for the player that enables the ClickDetector. This is my code so far:
function onClicked(click) h = click.Character:findFirstChild("Humanoid") if h ~= nil then h.Health = 1 script.Parent.Sound.Playing = true end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
How would I go about setting this up? Do I need remote events, a LocalScript, or what?
FYI if this is a really dumb question just know that I'm just starting out scripting.
To enable a ColorCorrection effect, you would need this line:
game:GetService("Lighting").ColorCorrection.Enabled = true
Instead, if you want to change a property on the ColorCorrection effect then you would need this example code:
game:GetService("Lighting").ColorCorrection.PropertyName = Value
Note that the PropertyName and the Value are your own choice. Here's an example that I'm changing the Brightness property on the ColorCorrection effect to 10:
game:GetService("Lighting").ColorCorrection.Brightness = 10
Well that does not entirely answer your question, to combine the line on the ClickDetector script, you would need to put the code I gave inside of the "onClicked" function. I'm using the first code in this case:
local function onClicked(click) game:GetService("Lighting").ColorCorrection.Enabled = true end script.Parent.ClickDetector.MouseClick:Connect(onClicked)
Although this script works, it makes the ColorCorrection enabled for everyone, so you would need to use a LocalScript to enable it on the client! If your eyes are sharp, you might notice that I added a "local" besides the word "function", it is better so you should use it. No much explanation because this is a beginner tutorial, also, consider using "Connect" not "connect", because "connect" is no longer used and "Connect" is much more recommended!
Also, LocalScript(s) does not function on Workspace or Lighting services, instead they work on the services that is called StarterGui or inside StarterPlayer, you would find two folders called "StarterPlayerScripts" and "StarterCharacterScripts". I will not be explaining what are their both difference is, but in this case I'd suggest putting it on StarterPlayerScripts. After the set-up, it will look like this in the StarterPlayerScripts.
Now, since script.Parent.ClickDetector
does not exist when LocalScript changed it's parent, we will need to locate the ClickDetector that is in Workspace. So we would need to replace the script.Parent.ClickDetector
to where ClickDetector is. If the brick is inside Workspace and the brick is named Part, then the code last line would be:
workspace.Part.ClickDetector.MouseClick:Connect(onClicked)
You should change the workspace.Part.ClickDetector
part to the location of the ClickDetector you want, though.
Full code (LocalScript):
local function onClicked(click) game:GetService("Lighting").ColorCorrection.Enabled = true end workspace.Part.ClickDetector.MouseClick:Connect(onClicked)