Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Don't know how to change lighting with an onTouch Event?

So I've recently tried to activate a lighting change from an onTouch event This is the script: function onTouch(part)

game.Workspace.ExposureCompensation = 2

end

script.Parent.Touched:connect(onTouch)

The only problem is that once I spawn in ExposureCompensation is already set to two, meaning it's already activating the script without me touching the block.

https://gyazo.com/cb6835b64879aa82caff7f56a9b5a70f

1 comment

0

Exposure = 0

1 answer

✓ Accepted answer

Something is touching the part immediately, causing Touched to fire.


You are not checking if it's an actual body part of a player's character. So it could be the baseplate touching it, and firing it immediately.

Simply check that it's a player touching it.


local Players, Workspace = game:GetService("Players"), game:GetService("Workspace");

script.Parent.Touched:Connect(function(part) --// pls use :Connect, :connect is deprecated
	local client = Players:GetPlayerFromCharacter(part.Parent);

	if (client) then
		Workspace.ExposureCompensation = 2;
	end
end);

If a player touched it, set ExposureCompensation to 2.

(is that a property now? i havent been on studio for 5 months straight)

Side note

In the gif you provided, you did not indent your code. Even if it's just one line, always indent your code. It makes code more readable, and makes it easier for debugging.


Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button below this answer. If you have any other questions, do leave them in the comments below.

1 comment

0

Could you answer my Q too it's an important one!

This discussion is preserved as it was. New answers, comments, and votes are closed.