Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make nice region system? How do I know if player entered the water and left it?

Imagine you have custom water (just a NonCollide anchored transparent block)

How do I know if player entered the water and left it?

I don't think it'll be a good idea to loop every time with :GetPartBoundsInBox() and compare it with some table with name (PlayersInWater for example) and check if new player entered or left the water. It'll be too unoptimized.

So you have any ideas? I could use .Touched event to see that player entered the water, but how do I know he left it?

2 answers

✓ Accepted answer

There is an event similar to .Touched called .TouchEnded, that could possibly work

You could try my module I made in my alt account. It basically uses workspace:GetPartsInPart() but it's kinda more advanced ig??? I promise to you it's great.

local region = workspace.Part -- imagine this is your region
local module = game.ReplicatedStorage.RegionPartService -- imagine you put my module in your game and put it in ReplicatedStorage

local RegionPartService = require(module)

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		while task.wait(1) do
			local isInside = RegionPartService:IsPartInRegion(region, char)
			if isInside then
				print("player is inside")
			else
				print("player is outside")
			end
		end
	end)
end)

Documentation

1 comment

0

Again it's not that good idea to loop over time.

This discussion is preserved as it was. New answers, comments, and votes are closed.