Area Scripting Dilemma

This is in many games when you walk near places it changes the color of the fog, the name pops up and fades away, etc. How would I go about implementing this feature?

I don’t understand how to use region3 with this, because there’s many parts blocking the way. Another problem with region3 is positioning, and sizing. I don’t really know how to size a region3 and position it where I want it to be. Magnitude works, but I want to specifically have a set range rather than a circle shaped area. If I use part touched systems I have to keep in mind players may spawn without touching anything and then nothing would happen at all as well as touched being fired every time a player walks through the part.

3 Likes

You can use Parts.

You just need a default fog colour and a debounce so that it wouldn’t fire more than once.

Using .touched for a system like this doesn’t offer much flexibility. It works but you’d have an absolute ton of signals that likely aren’t necessary. Not to mention that this event will fire if any part touches something.

Instead of doing this, have a while loop iterate through a list of areas or “zones” and check when a player’s root is inside of that area. These cube regions will be used to scan anything inside of it, similar to how Region3 works.

For example:

local function getZone(playerPos)
	local abs = math.abs
	for index,part in pairs(areas) do -- you could use a mixed table instead of the part name
		local relativePos = part.CFrame:pointToObjectSpace(playerPos)
		local bounds = part.Size/2

		if abs(relativePos.x) < bounds.x and abs(relativePos.y) < bounds.y and abs(relativePos.Z) < bounds.z then
			return part.Name
		end
	end
	return nil
end

Using the above alongside a while true loop, you can check what zone the player is actively in, and then perform a certain action based on the type of zone they are in. While I won’t fully solve the issue of dynamically changing fog or music or even the title of the area you are in appearing, this should be enough to help you out. Let me know if you need any more help!

2 Likes

When I use parts it works better for me, but the only dilemma there is that sometimes it doesn’t run the touched function when i’m clearly walking through the area brick. This is due to a debounce issue, and the fact that once it runs once you cross it, it will not run twice because you’re walking in it unless you jump. Why is this even a thing? Why can’t It simply just run touched when you’re inside or touching it properly.

u could put parts of the map into folders and use floor raycasts to check which folder its in
u would need to design ur map around it though

how about this?