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

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.