I need help making a script where when it is touched something happens

Hey,
I am trying to get into scripting but have very limited knowledge on a few things.
I need to know how to make a script where when a part is touched, then the saturation of the screen changes.
I’m not sure if you’re able to change properties of ColorCorrection in a script, but if someone can help I’d greatly appreciate it.

I believe it’s possible to do that via the Touched event, what you can do is make the part have the Touched event and change the properties there

Let’s say your script is in the part itself, the code woudl look something like

script.Parent.Touched:Connect(function()
   --Code here to change the saturation
end)

This is a basic example, meaning anything that touches it will cause the event to run, you’ll have to do some if statements to check if who touched the part is a player, which if needed, I can help with

1 Like

If you want to change the saturation of a player’s screen when he touches a part, you’ll need to have 2 scripts, 1 in the part and the other in StarterGui or StarterPlayerScripts, really doesn’t matter.

–Server Script

local saturationOnTouch = -1 --Saturation the screen will change to
local remoteName = "ScreenSaturation" --The remote's name, if you want to change it you'll have to     do it on the client script too.
local remote = game.ReplicatedStorage:FindFirstChild(remoteName) or Instance.new("RemoteEvent",game.ReplicatedStorage) --Finding a RemoteEvent or creating 1
remote.Name = remoteName 

script.Parent.Touched:Connect(function(part) --Check when something touched the part
	local plr = game.Players:GetPlayerFromCharacter(part.Parent) --Check if that part's parent is a player
	if plr then --If it is a player then
		remote:FireClient(plr,saturationOnTouch) --Tell the client to change the saturation to saturationOnTouch
	end
end)

–Client script

local remote = game.ReplicatedStorage:WaitForChild("ScreenSaturation") --Waits for the remote

local color = Instance.new("ColorCorrectionEffect") --Creating a color correction effect

color.Parent = game.Lighting --Puts it in lighting

remote.OnClientEvent:Connect(function(sat)

color.Saturation = sat

end)
1 Like

You can add a color correction in replicated storage and clone it into the lighting service. If it’s a script then it will clone to all the player’s lighting service. But if you want to make it only into the specific person that touched the parts’ lighting service then you have to use a Local Script, and It can be added in the gui editor.

Blockquote
–Server Script ({Server Sided Script} Added Into The Touched Part)
local colorceffect = game.ReplicatedStorage:WaitForChild(“ColorCorrection”) --Gets the color correction from Replicated Storage
local debounce = false
Script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid) ~= nil then
if debouce == false then
debounce = true
local ccec = colorceffect:Clone()
ccec.Parent = game:GetService("Lighting)
else
wait(1)
debounce = false
end
wait(1)
debounce = false
end)

–Local Script ({Client Sided Script} Added into starter gui)
local colorceffect = game.ReplicatedStorage:WaitForChild(“ColorCorrection”) --Gets the color correction from Replicated Storage
local debounce = false
local part = game.Workspace:FindFirstChild(“Part”) --The part that’s in the workspace
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid) ~= nil then
if debouce == false then
debounce = true
local ccec = colorceffect:Clone()
ccec.Parent = game:GetService("Lighting)
else
wait(1)
debounce = false
end
wait(1)
debounce = false
end)

1 Like