Trying to make a gui pop up when you are in your team's base and disappear when you walk out

I’ve been trying to get this to work for about an hour, and i cant for some reason.

my team is blue, the lower and upper corner is in a folder named Region3Test, i am on team blue, the screengui is in startergui, the screengui is called screengui, the frame is called TeamFrame, there is a text label in the frame that says hi, here is my code.

local myRegion = Region3.new(workspace.Region3Test.LowerCorner.Position, workspace.Region3Test.UpperCorner.Position)
local player = game:GetService("Players").LocalPlayer
local UI = player.PlayerGui:WaitForChild9("ScreenGui")
local isInside = false

game:GetService("RunService").Heartbeat:Connect(function()
	local humanoid = workspace:FindPartsInRegion3WithWhiteList(myRegion, {script.Parent.HumanoidRootPart})
	if #humanoid > 0 and player.Team == game:GetService("Teams")["Blue"] then
		print("Teammate found!")
		if not (UI.TeamFrame.Visible) then
			UI.TeamFrame.Visible = true
		end
	else
		if (UI.TeamFrame.Visible) then
			UI.TeamFrame.Visible = false
		end
	end
end)

what the hell am i doing wrong?

@daslick can you help me with this? not sure whats wrong…

What is the issue? I can’t help you if I don’t know what’s wrong.

read the above reply with the script, please

Again, I don’t know if there’s no output, if the script isn’t working, or if there is an error.

Looking through the code, it seems like there’s a syntax error on line 3

local UI = player.PlayerGui:WaitForChild9("ScreenGui")

where you have a 9 after the WaitForChild.

local UI = player.PlayerGui:WaitForChild('ScreenGui')

@daslick

thank you, but my foolishness created that error recently so it was not the problem. i fixed it and even copied the code daslick provided and it didnt solve the problem. i have:

-the code in a local script, in starter character scripts
-parts named LowerCorner and UpperCorner in a folder named Region3Test in the workspace
-my team is called Red and i am on that team, i replaced “myTeam” with Red and it didn’t work
-the gui is called ScreenGui and the frame that is a child of the gui is TeamFrame and this is in startergui

i’m not sure what is wrong, do you have any idea?

here is a link to the model of all the parts:
https://www.roblox.com/library/5431786622/Red

Region3.rbxl (22.9 KB)

local TeamGui = game.ReplicatedStorage:WaitForChild("TeamGui", math.huge)
local Player = game.Players.LocalPlayer
local Lower = game.Workspace.Region3Test.LowerCorner
local Upper = game.Workspace.Region3Test.UpperCorner
local min = Lower.Position - (0.5 * Lower.Size)
local max = Upper.Position + (0.5 * Upper.Size)
local Region = Region3.new(min, max)
local VisualizePart = false


if VisualizePart then
	local Visualize = Instance.new("Part", workspace)
	Visualize.Anchored = true
	Visualize.Transparency = 0.5
	Visualize.Color = Color3.fromRGB(255,0,0)
	Visualize.CanCollide = false
	Visualize.Size = Region.Size
	Visualize.CFrame = Region.CFrame	
end


local LastGui = nil
while true do
	wait()
	local Parts = game.Workspace:FindPartsInRegion3WithIgnoreList(Region, {Upper, Lower}, math.huge)
	local IsIn = false
	for i,v in pairs(Parts) do
		local PlayerCharacter = Player.Character or Player.CharacterAdded:Wait()
		if PlayerCharacter and v.Name == "HumanoidRootPart" and Player.Team == game:GetService("Teams")["Red"] then
			if v.Parent == PlayerCharacter then
				IsIn = true
			end
		end
	end
	if IsIn then
		if LastGui == nil then
			local NewGui = TeamGui:Clone()
			NewGui.Parent = Player.PlayerGui
			LastGui = NewGui
		end
	else
		if LastGui then LastGui:Destroy() LastGui = nil end
	end
end
3 Likes

bruhest moment on this forum. thank you so much.