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

Region3 or Raycasting for checking player's area?

Asked by
trecept 367 Moderation Voter
6 years ago
Edited 6 years ago

I have a lobby and an arena, as simple as possible I want the player's maxhealth to increase to infinite in the lobby and back to 100 in the arena. The obvious choice is to create a big false cancollide invisible block, and have a touched event in the part changing health. I don't want to do this because it's extremely exploitable (exploiters can move the part, change the part's size, bring the part, delete the part etc) and there's too many things to prevent.

I want to use either Region3s (exploiters can't "bring" a region3) or Raycasting as it's more secure and I believe a better method. I'm unsure if using a Region3 will lag my game if the lobby has lets say over 500 parts in it, or if Raycasting is better performance wise and in general? Which one is best for performance and security/efficiency? Thanks.

EDIT:

I just checked, using a while wait() loop with Region3 in my lobby doesn't seem to cause much lag, but when there are more players it probably will, the lobby has around 550 parts.

1 answer

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Region3 would be the best method out of the two. If you were to use Region3s to detect characters, you could iterate through all the players and add their characters to a whitelist, and use FindPartsInRegion3WithWhiteList with this list:

local function GetWhitelist()
    local Whitelist = {}
    for _,Plr in pairs(Game.Players:GetPlayers()) do
        if Plr.Character then
            table.insert(Whitelist,Plr.Character)
        end
    end
    return Whitelist
end

You would then get the characters from the body parts that the Region3 picked up, and check which ones are within and without the region.

You shouldn't worry about lag for regions over large areas, they are pretty efficient and the whitelist should ignore extra parts (reducing lag from a larger number of parts). Basically, Region3s were designed for this.

However, you are also able to use Touched and TouchEnded with an invisible part. Even though exploiters can move the parts with their local scripts, if you have FilteringEnabled this change will not replicate to the server. This means that the server still sees the part in the same location and will still detect when the exploiter begins/ends touching the part. But due to the potential glitchyness of the touch events, Region3s may still be the better option.

0
I see, thank you! Would it still be better using a wait amount like 1 second instead of while wait() do? Or is it really efficient enough not to lag the server? trecept 367 — 6y
1
I really think lag shouldn't be a problem, but you can compare the tick() before and after you handle all the region3 stuff to find out exactly how long it takes. mattscy 3725 — 6y
Ad

Answer this question