I have a localscript that checks if a player has stepped on an Area and if they have a gui pops up as long as no one owns that area. Is this optimal? Or could it be simplified for less potential Lag.
local Players = game:GetService(“Players”)
local RunService = game:GetService(“RunService”)
local Player = Players.LocalPlayer
local Gui = script.Parent
local TouchAreas = workspace:WaitForChild(“TouchAreas”)
local param = OverlapParams.new()
param.FilterType = Enum.RaycastFilterType.Whitelist
----Getting the view and exit view buttons
local AreaViewGui = script.Parent.Parent:WaitForChild(“AreaView”)
local View = AreaViewGui.View
local connection
connection = RunService.RenderStepped:Connect(function()
local Character = Player.Character
local AreaOwned = Player:WaitForChild(“AreaOwned”)
task.wait(.1)
param.FilterDescendantsInstances = {Character.PrimaryPart}
for i, area in pairs (TouchAreas:GetChildren()) do
local Overlap = workspace:GetPartsInPart(area, param)
if #Overlap > 0 then ------ Runs if the area has more than one player
local ZoneFolder = game.Workspace.Areas:WaitForChild(area.Name)
local Owner = ZoneFolder:FindFirstChild("Owner")
if AreaOwned.Value == "None" and Owner.Value == "None" then
Gui[area.Name].Visible = true
else
Gui[area.Name].Visible = false
end
if Owner.Value ~= "None" then ---Checking the players owned area to display the view gui.
local OwnerValueStore = Owner.Value
end
else
end
end
end)