Detecting player in a dark place

Someone knows how to detect if the player is in dark place Like:

Example script: (LOCAL SCRIPT)


local function IsDark()
   if dark then 
		print("Its dark")
		return true
   else
		print("Not dark!")
		return false
   end
end

while task.wait() do
    local dark = IsDark()
end


1 Like

Thereā€™s no way to detect the amount of light cast on any instance, hence you canā€™t really make this.

Iā€™d suggest manually creating ā€œzonesā€ where you know itā€™ll be dark, and then just check if the player is inside one of those zones.

1 Like

You could check the pixel colors using editable images, but itā€™s just way easier to add zones

1 Like

You could, but thatā€™s not counting how some UGC are not affected by light on purpose (eg. cartoony outline), which would lead to some parts of the player always being set to rgb 0,0,0 and tripping up your system.

1 Like

an alternative method is to do raycasts from avatar to the outside. if more than a threshold % of those raycast hit something, then we are ā€˜in enclosureā€™.
It can distinguish outdoor area from non-illuminated caves/rooms/etc. but this cannot know if a portion of indoor area is lit or not.

zones feel much easier to work with

1 Like