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

How i can tweak the camera by touching a part?

Asked by 3 years ago

I am creating a scary game and I would like to know how to alter the camera so that saturation goes up and down suddenly as a function of jumpscare

Notice this is my first time scripting so I am 100% sure this is wrong

local part = script.Parent
local camera = workspace.CurrentCamera
local function onPartTouched(otherPart)
    -- Get the other part's parent
    local partParent = otherPart.Parent
    -- Look for a humanoid in the parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        -- Do something to the humanoid, like set its health to 0
        workspace.CurrentCamera.ColorCorrection.Saturation = -100
        wait(0.1)
        workspace.CurrentCamera.ColorCorrection.Saturation = 0
        wait(0.1)
        workspace.CurrentCamera.ColorCorrection.Saturation = -100
        wait(0.1)
        workspace.CurrentCamera.ColorCorrection.Saturation = 0
        wait(0.1)
        workspace.CurrentCamera.ColorCorrection.Saturation = -100
        wait(0.1)
        workspace.CurrentCamera.ColorCorrection.Saturation = 0
        wait(0.1)
        workspace.CurrentCamera.ColorCorrection.Saturation = -100
        wait(0.1)
        workspace.CurrentCamera.ColorCorrection.Saturation = -100
        wait(0.1)
        workspace.CurrentCamera.ColorCorrection.Saturation = 0
        wait(0.1)
        workspace.CurrentCamera.ColorCorrection.Saturation = -100
        wait(0.1)
    end
end

part.Touched:Connect(onPartTouched)

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

ColorCorrection isn't a property of the Camera, it's an effect you can place into the Lighting. If you have a ColorCorrection effect in Lighting named "ColorCorrection", it would be located in game.Lighting.ColorCorrection.

Some other things I noticed: - Whenever you find yourself copy and pasting code, you should stop and write a loop instead.

  • You should add a debounce to make sure the jumpscare can't happen if it's already happening. Often when a character touches a part, multiple parts of it touch, so your effect might last a lot longer than you expected.

  • If this is in a server script, every player will see it. If you only want the player who touched the part to see the effect, take a look at RemoteEvents

Add a ColorCorrection effect into Lighting and then use this script (I just used the default name but if you changed it, change the name in the script)

local part = script.Parent
local debounce = false

local function onPartTouched(otherPart)
    -- Get the other part's parent
    local partParent = otherPart.Parent
    -- Look for a humanoid in the parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
        if not debounce then
            debounce = true
            -- Do something to the humanoid, like set its health to 0
            for i = 1, 10, 1 do
                wait(.1)
                game.Lighting.ColorCorrection.Saturation = -100
                wait(.1)
                game.Lighting.ColorCorrection.Saturation = 0
            end
            debounce = false
        end
    end
end

part.Touched:Connect(onPartTouched)
0
This works thank you, this is my first time doing these things so im pretty much new XEPHTHEKITSUNE 2 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
local target = nil -- locate the PART you wanna touch not model, part
target.Touched:Connect(function(hit)
local cam = workspace.CurrentCamera
local colorCorrection = cam.ColorCorrection.Saturation
for i = 1, 50 do 
colorCorrection = -100
wait()
colorCorrection = 0 
end
colorCorrection = 0
end)

Any errors, tell me, I havent yet checked the code to see if color correction is a valid member to script

Answer this question