My game has a safezone that prevents pvp from happening. The system I made worked as intended but I dont think this is how other developers made their Safezone system.
Basically, when people touch the green part, their SafeZone bool value is set to true, and when they touch the red part, the bool is set to false. I dont really like my way of making safezone systems because it can be quite tedious to resize the zones.
Theres a little problem, it only works about 75% of the time. Sometimes when i enter the zone the touchended event fired last. Heres my code:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Safe") then
print("hot")
hit.Parent.Safe.Value = true
end
end)
script.Parent.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Safe") then
print("not hot")
hit.Parent.Safe.Value = false
end
end)
Well, i think this is your choice, for example, when i was about to make a war game, i just thought about make something like this, but i didn’t, other developers are using another system because they can modify it more easier, it depends about if that can be exploited or not, or using bad practices codes or not. This is your choice, and you can keep your system, because i think it’s good. But i recommend you keep the red walls with more distance from the green block. But i repeat, i recommend you keep your system.
Touched/UnTouched events are unreliable due to their nature of firing unpredictably and often sometimes never at all. These methods can also cause noticeable lag when complex geometries enter them, therefore it’s best to avoid them for situations like this.
I recommend using GetPartsInRegion3 for rectangles or a combination of that and raycasting for other shapes, as explained here.