I'm trying to make a shop gui that'll appear and disappear depending on if the player is in the correct area. The Gui appears when you enter the region, but won't go away. Script:
local RegionPart = workspace.GemTradeVisual local Region = Region3.new(RegionPart.Position - (RegionPart.Size/2),RegionPart.Position + (RegionPart.Size/2)) local Detected = false local Player = game:GetService("Players").LocalPlayer local Char = Player.Character or Player.CharacterAdded:Wait() wait() RegionPart:Destroy() while wait(1) do local Detect = workspace:FindPartsInRegion3WithWhiteList(Region,game.Players.LocalPlayer.Character:GetDescendants(),math.huge) for _,v in pairs(Detect) do if v.Parent.Name == Player.Name then Detected = true break else Detected = false print(v) end end if Detected then Player.PlayerGui.SellGems.Enabled = true else Player.PlayerGui.SellGems.Enabled = false end end
You already whitelisted the LocalPlayer, you don't need to check if they are in the circle. Any parts collected will be a part of that player.
local RegionPart = workspace:WaitForChild("GemTradeVisual") local Region = Region3.new(RegionPart.Position - (RegionPart.Size/2),RegionPart.Position + (RegionPart.Size/2)) local Player = game:GetService("Players").LocalPlayer local Char = Player.Character or Player.CharacterAdded:Wait() local SellGems = Player.PlayerGui:WaitForChild("SellGems") wait() RegionPart:Destroy() while wait(1) do local Detect = workspace:FindPartsInRegion3WithWhiteList(Region,Char:GetDescendants(),math.huge) SellGems.Enabled = #Detect > 0 end