Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

0
Exposure = 0 Sapppower 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.


```lua 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.
0
Could you answer my Q too it's an important one! Sapppower 17 — 5y
Ad

Answer this question