How to get the duration of a player's stay in the zone?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want that when a player enters a special zone, then I can get his stay time in this zone.
    (To be more precise, I would like, for example, if a player stands in a certain zone for a certain amount of time, then he gets badge.)
  2. What is the issue? Include screenshots / videos if possible!
    I haven’t needed this before, so I can’t figure out how to implement it.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried to find a solution here, but it seems there are no cases similar to mine. So far I tried using Region3 and :GetPartsInPart(), but I couldn’t figure out how to use them for my purposes.

The main thing I need is a way to get the duration of a player’s stay in a certain zone at any time.
I will be very grateful if someone helps me with this.

You can shoot a ray cast from the character downwards, check if it hit the zone and do some debounce system

and for example you’ll have a variable detecting if the player is in the zone

local IN_ZONE = false
local IN_TIME = 0
-- do ur hacky stuff here
while true do -- this part is at the end of your code :^
   if IN_ZONE == true then
      task.wait(1)
       IN_TIME += 1
   end
end

Use the ZonePlus module which uses the SpatialQuery API: Introduction - ZonePlus
Simply connect the playerEntered and playerExitted events to a table of player times. When they enter, increment their time by 1. When they leave, don’t increment it.

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