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

Script that activates when camera is in part?

Asked by 5 years ago

So this script I have makes it to when your camera is in a part, it adds a ColorCorrection to Lighting, and changes the fog. I tried to make it to where when the camera is not in the part, the ColorCorrection and fog change to normal. But this doesn't seem to be working.

while wait(rate) do
    if game.Workspace.CurrentCamera then
        local campos=game.Workspace.CurrentCamera.CoordinateFrame.p
        for _,v in pairs(game.Workspace:FindPartsInRegion3(Region3.new(campos,campos))) do
            if v and v.Name=="Water" then
            UnderWaterColor.Parent = Lighting
            UnderWaterColor.TintColor = Color3.fromRGB(98, 148, 255)
            Lighting.FogStart = 0
            Lighting.FogEnd = 75
            Lighting.FogColor = Color3.fromRGB(83, 136, 192)
            end
        end
    end
end

while wait(rate) do
    if game.Workspace.CurrentCamera then
        local campos=game.Workspace.CurrentCamera.CoordinateFrame.p
        for _,v in pairs(game.Workspace:FindPartsInRegion3(Region3.new(campos,campos))) do
            if v and v.Name == nil then
            UnderWaterColor.Parent = script
            Lighting.FogStart = fogstart
            Lighting.FogEnd = fogend
            Lighting.FogColor = fogcolor
            end
        end
    end
end

the rate is 0.000001, and I even tried making an invisible Air part all around the map, and I replaced "If v and v.Name =="Air" then" but that doesn't work either. I'm not sure where to go about this.

1 answer

Log in to vote
0
Answered by 5 years ago

I'm not sure why you're having WaterColor change parent.. In my testing I took that out.. Put the code in a LocalScript and added it to my StarterPlayerScripts and this definitely works, so maybe this would help.. Also I'm doing an ELSE so we don't have to have two while loops for running the check:

local Lighting = game.Lighting
local fogstart =500
local fogend = 1000
local fogcolor = Color3.fromRGB(98, 148, 255)
local rate = .5
while wait(rate) do
    if game.Workspace.CurrentCamera then
        local campos=game.Workspace.CurrentCamera.CoordinateFrame.p
        for _,v in pairs(game.Workspace:FindPartsInRegion3(Region3.new(campos,campos+Vector3.new(3,3,3)))) do

            if v and v.Name=="Water" then
           -- UnderWaterColor.Parent = Lighting
          --  UnderWaterColor.TintColor = Color3.fromRGB(98, 148, 255)
                Lighting.FogStart = 0
                Lighting.FogEnd = 75
                Lighting.FogColor = Color3.fromRGB(83, 136, 192)
                print("YOU are in the water!!!")
            else
                Lighting.FogStart = fogstart
                Lighting.FogEnd = fogend
                Lighting.FogColor = fogcolor
                if v==nil then
                    print("V is nil")
                end
            end
        end

    end
    print("got here")
end
--[[
    while wait(rate) do
    if game.Workspace.CurrentCamera then
        local campos=game.Workspace.CurrentCamera.CoordinateFrame.p
        for _,v in pairs(game.Workspace:FindPartsInRegion3(Region3.new(campos,campos))) do
            if v and v.Name == nil then
           -- UnderWaterColor.Parent = script
            Lighting.FogStart = fogstart
            Lighting.FogEnd = fogend
            Lighting.FogColor = fogcolor
            end
        end
    end
end

    ]]


Ad

Answer this question