Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago
Edited 1 year ago

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

Log in to vote
1
Answered by
NykoVania 231 Moderation Voter
1 year ago

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

Ad
Log in to vote
-1
Answered by 1 year ago
Edited 1 year ago

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

0
Again it's not that good idea to loop over time. ArtemVoronin0 171 — 1y

Answer this question