I have a system with 4 areas that I want to detect if the players are in. I have one RenderStepped loop that uses a table of the 4 areas to loop through to see if, one: the player is in an area and has not yet claimed an one and two: if they have claimed an area and are in their own. If they are in their own area then they should be able to open their area gui. I want to know if this is the most effective way to do it since it will always be running as I’ve heard there might be more game efficient options out there.
Code:
local Players = game:GetService(“Players”)
local RunService = game:GetService(“RunService”)
local Player = Players.LocalPlayer
local Gui = script.Parent ---- (A gui containing all 4 “Claim” buttons for the areas)
local TouchAreas = workspace:WaitForChild(“TouchAreas”)
local param = OverlapParams.new()
param.FilterType = Enum.RaycastFilterType.Whitelist
local OpenButton = script.Parent.Parent.Screen.Open —The players gui that should only show if their
in their area
RunService.RenderStepped:Connect(function()
local Character = Player.Character
if not Character then return end
param.FilterDescendantsInstances = {Character.PrimaryPart}
for i, area in pairs (TouchAreas:GetChildren()) do
local Overlap = workspace:GetPartsInPart(area, param)
if #Overlap > 0 then
local AreaOwned = Player:FindFirstChild("AreaOwned")
if AreaOwned.Value == "None" then
Gui[area.Name].Visible = true ----This determines whether to show the "Claim" Gui
else
Gui[area.Name].Visible = false
end
if AreaOwned.Value.."Touch" == area.Name then
OpenButton.Visible = true --- This is the players area Gui
end
else
Gui[area.Name].Visible = false
local AreaOwned = Player:FindFirstChild("AreaOwned")
if AreaOwned.Value.."Touch" ~= area then
OpenButton.Visible = false
end
end
end
end)