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

what does this mean? i am trying to make a regional fog local script but it just wont work

Asked by 3 years ago

i am using this script with a part in the exact spot its looking for

local Lighting = game:GetService("Lighting")

local detectionPart = game.Workspace.FogDetectionPart
local localPlayer = game.Players.LocalPlayer


local function enableFog()
    Lighting.FogEnd = 250
    Lighting.Brightness = 1
    Lighting.Ambient = Color3.fromRGB(100, 100, 100)
    Lighting.OutdoorAmbient = Color3.fromRGB(50, 50, 50)
    game.Lighting:SetMinutesAfterMidnight(300)
end

local function disableFog()
    Lighting.FogEnd = 100000
    Lighting.FogStart = 0
end

detectionPart.Touched:Connect(function()
    -- This is just to add a TouchInterest
end)

local touching = false

while true do
    local foundPlayer = false
    for i,v in ipairs(detectionPart:GetTouchingParts()) do
        if v.Parent.Name == localPlayer.Name then
            foundPlayer = true
        end
    end

    if touching and not foundPlayer then
        -- Player is no longer in detection part
        disableFog()
        touching = false
    end

    if not touching and foundPlayer then
        -- Player is now in detection part and wasn't before
        enableFog()
        touching = true
    end

    wait(.5)
end

but it keeps giving me the error of

FogDetectionPart is not a valid member of Workspace "Workspace"

i dont know what this means, someone help please

1 answer

Log in to vote
0
Answered by 3 years ago

It's saying it can't find the part in workspace. Try waiting for the part to load in:

--line 3
local detectionPart = game.Workspace:WaitForChild("FogDetectionPart")

If that doesn't work then the part is probably parented to something else.

Ad

Answer this question