I need to detect if LocalPlayer is in Region3
local plr = game.Players.LocalPlayer while 1 do if(plr.IsInRegion3 == "RegionName") then --this is obviously wrong, I need a solution for this --Do something wait(0.1) end
You need to utilize the workspace.FindPartsInRegion3WithWhiteList function. You can call the function with the character model in the whitelist every frame or two, that's up to you to decide. Calling the function with only a whitelist that allows ~20 parts doesn't make it too expensive to run every frame. Of course if you don't need to call it that often, it's simple to optimize. Keep track of the last update and see if enough time has passed since.
local RunService = game:GetService("RunService") local Players = game:GetService("Players") local localPlayer = Players.LocalPlayer local region = Region3.new(Vector3.new(-10, -10, -10), Vector3.new(10, 10, 10)) -- local function isPlayerInRegion(player, region) local partsInRegion = workspace:FindPartsInRegion3WithWhiteList(region, {player.Character}) return #partsInRegion >= 1 end local function regionUpdate() if localPlayer.Character then local localPlayerIsInRegion = isPlayerInRegion(localPlayer, region) localPlayer.Character.Head.BrickColor = localPlayerIsInRegion and BrickColor.Green() or BrickColor.Red() end end -- RunService.Heartbeat:Connect(regionUpdate) -- No reason to do it before the frame is drawn by binding to the RenderStepped event, using Heartbeat here is the best