Depending on how big the region is, Touched will work fine. You can use some math though if you want to detect if a point is inside another point.
Looking on the wiki it does not appear that there is a direct event that fired when a region3 is touch or entered. So Iâm pretty sure the only way to do this is set up a loop that calls the workspace:FindPartsInRegion3 function and get the return values. If you wanted you could hook the function up to an event so that when a part is found, it fires a remote to all the clients.
heres the wiki class if you want to check it out, there arenât too many properties or functions.
Not sure how efficient this would be but perhaps just a heartbeat or a runservice constantly checking that region?
At that point itâd be more efficient to use math.
@Planet_Dad if you wish to let the server know what the user is touching just do the region3 serverly and then do Region3withwhitelist. and then whitelist everycharacter go through the list that it returns and check for any humanoidrootparts then get the player by Game.Players:GetCharacter(HumanoidRootPart.Parent)
Isnât that what I said, minus the remote Event part?
if the region is big use a touched event if its small use a while loop to check if player is in region
these are basically map voting pads the player stands on, it sounds like part.Touched:Connect might be the most sensible because it has an event.
The only reason i was thinking Region3 was because i heard the part touched was unreliable
Touched is 100% reliable, depending on which enviroment you use it on. On the client it is far more âreliableâ, the server sometimes misses some events due to latency and other reasons. TouchEnded however is extremely unreliable, and I would recommend using math if you need to use TouchEnded.
Some examples of math you could use is Magnitude or some formulas.
Touched is pretty reliable, TouchEnded is not.
Oh i definitely need TouchEnded because when they step off, they get removed from a table.
Yes for what youâre doing it doesnât sound like TouchEnded is a good choice. A simple Region3 while loop as others have mentioned would be fine, I wouldnât bother with connecting it with heartbeat cause a tiny bit of lag isnât going to matter over a map voting pad. OverHashâs idea with Magnitude would also work, though if you choose this I would make sure your button is a circle.
If I am doing TouchEnded, then the Region3 isnt really needed.
how unreliable is TouchEnded?
This is really supposed to be something so simple. A player stands on a pad, they get added to a table, they step off, they get removed.
TouchEnded tends to fire randomly even when playerâs are still touching the part. If I remember right animations tend to mess it up including idle animations. You could always try it out for yourself of course in studio.
Region3 would be my last goto, math is better. If you need help lemme know
This is kinda the direction Iâm thinking I might go with. This doesnât need to be a robust system, just simple and quick is whatâs needed here.
EDIT: It has come to my attention that people are liking this post. The code below does not work correctly, because it creates a region3 everytime the part is touched, instead of creating the regions once and referencing them.
DO NOT use the code below. Let me be clear, do not use the code. Region3âs are perfectly fine.
This is what I am using for my game. It creates a Region3 when a part in a table is touched, and checks if whatever touched it is still touching using FindPartsInRegion3. If the table of parts in the Region3 is nil, then the loop for checking stops until the next touch. I edited it a little bit without testing, but I think it should work still. The whitelist is where you would keep the part that touches the other part.
local TableOfParts = FolderOfParts:GetChildren()
for _,v in pairs(TableOfParts) do
v.Touched:Connect(function(ThingThatTouchedOneOfTheParts)
local CurrentWater = v
local Min = CurrentWater.Position - (0.5 * CurrentWater.Size)
local Max = CurrentWater.Position + (0.5 * CurrentWater.Size)
local Region = Region3.new(Min,Max)
local Whitelist = {CertainPart}
while wait(.1) do
local CheckField = workspace:FindPartsInRegion3WithWhiteList(Region, Whitelist)
if CheckField[1] == nil then
else
end
end
end
else
end
else
end
end)
end
Maybe not the most efficient, but itâs reliable.
NodeSupport , you are one of the Smartest People in the Entire Universe. I just Used this Method. Its Great! If I could Award you with A Badge , I would!
Your Post Saved Me and My Game!
I am forever thankful!
I recommend you look into Zone+ module. It is VERY nice and I use it for all sorts of stuff! Safe Zones, hit boxes, tycoon button detectors, you name it!
It has events