Oh that’s quite simple, I presume you’re going to use a region if the part goes over everywhere that should be dark
First, the localscript must be somewhere where it can run, I’d recommend StarterPlayerScripts.
Then, set up a region using that invisible part you’re mentioning, and every frame (if doesn’t cause problems), check if the player’s character is in the region, and if it is, change the density, otherwise, keep it at 0.75. For this, we’ll use FindPartsInRegion3WithWhiteList()
, with it only caring for your character.
We’re going to use Region3s because TouchEnded is a bit weird sometimes
Here’s an example of what you could use
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local regionPart = --The part to use
local size = regionPart.Size * 0.5
local pos = regionPart.Position
local region = Region3.new(pos - size, pos + size)
while true do
RunService.Heartbeat:Wait()
if not char then
char = player.Character or player.CharacterAdded:Wait()
end
local condition = #workspace:FindPartsInRegion3WithWhiteList(region, {char}) > 0
Lighting.Atmosphere.Density = condition and 0 or 0.75
end
Every frame it checks if the character doesn’t exist in the variable and if it doesn’t, it gets the character again and then checks if it found the character in that region and changes the density accordingly
Lighting.Atmosphere.Density = condition and 0 or 0.75
If the condition was true, then set density to 0, if it was false, set it to 0.75
You’;d have to change it around to include more than 1 zone
Although I think it would be the best approach to use ZonePlus v2 to determine if they’re in the zone or not