Making a textLabel (or something) floating above an area on the map?

Trying to do something like this:

with this:


Bunch of parts and Unions inside of folders, want to make a textlabel above the entire territory of each,
but I dont know how to make a textlabel find the size of the entire folder.
(my first thought)
Don’t really know where to start, but I have seen it done on roblox before with Global Conflict II.

1 Like

You could probably start with finding a bounding box of the folder, then you’d just make a part that spans this bounding box and add a text label to the top via surfacegui. Really you’d just compare each corner of each part in that folder, then compare it to your current lower and upper bounds, if it’s further than each of these boundaries, you’d take that vector and use it as your new lower/upper boundary.

Unless your map is 2d then you’d just use a text label without the surface gui (but judging by the shadows I’m guessing it’s 3d).

But anyway, here’s some pseudocode about how you might go about finding an axis-parallel bounding box of the country:

local inf = math.huge

local lowerX, upperX, lowerY, upperY = 0,0,0,0
for each part in the folder do
    get each corner of this part
    for each corner do
        if corner.X < lowerX then lowerX = corner.X
        if corner.Y < lowerY then lowerY = corner.Y
        if corner.X > upperX then upperX = corner.X
        if corner.Y > upperY then upperY = corner.Y

If you don’t want to write your own bounding box algorithm you could also just use model:GetBoundingBox but as you said, you’re working with folders so this might not be possible.

1 Like

ill try this, sorry for the late response, i’m working on my notification system (same game)

Also, what do you mean by corner?

Just confused on implementation, I don’t know how to get the corners

local NationsFolder = workspace.Nations
local x = 0
local xmin = 0
local z = 0
local zmin = 0
local lastz = 0
local lastx = 0
local y = 5

–box algorithm
for i, nation in pairs(NationsFolder:GetChildren()) do
for i, child in pairs(nation:GetChildren())do
if child:IsA(“Part”) or child:IsA(“UnionOperation”) then
local xpos = child.Position.X
local zpos = child.Position.Z
lastx = xpos
lastz = zpos
if xpos > x then
x = xpos
elseif xpos < xmin then
if i > 0 then
if xpos < lastx then
xmin = xpos
end

			end
			xmin = xpos
			
		end
		if xpos > z then
			z = xpos
		elseif zpos < zmin then
			if i > 0 then
				if zpos < lastz then
					zmin = zpos
				end
				local minpart = Instance.new("Part")
				minpart.Anchored = true
				minpart.Position = Vector3.new(xmin,y,zmin)
				minpart.Parent = workspace
				local maxpart = Instance.new("Part")
				maxpart.Anchored = true
				maxpart.Parent = workspace
				maxpart.Position = Vector3.new(x,y,z)
				print(xmin,y,zmin)
				print(x,y,z)
				
			end
				 
			

		end
		
	end
end

end

result: totally botched, spawns in parts at like 300,5,50 position, send help

Finally. My sanity is gone; my work is complete.

local y = 10
function destroyWall()
	for i, thing in pairs(NationsFolder:GetDescendants()) do
		print(thing.Name)
		if thing.Name == "Wall" then
			thing:Destroy()
		end
	end
end

for i, nation in pairs(NationsFolder:GetChildren()) do

	local firstPart = true
	local x, xmin, z, zmin
	local NationsFolder = workspace.Nations
	local y = 10

	for i, nation in pairs(NationsFolder:GetChildren()) do
		local firstPart = true
		local x, xmin, z, zmin

		for i, child in pairs(nation:GetChildren()) do
			wait(.00001)
			if child:IsA("Part") or child:IsA("UnionOperation") then
				if firstPart then
					firstPart = false
					x = child.Position.X
					xmin = child.Position.X
					z = child.Position.Z
					zmin = child.Position.Z
				else
					local xpos = child.Position.X
					local zpos = child.Position.Z

					if xpos > x then
						x = xpos
					elseif xpos < xmin then
						xmin = xpos
					end

					if zpos > z then
						z = zpos
					elseif zpos < zmin then
						zmin = zpos
					end
				end
			end
		end

		local wall = Instance.new("Part")
		wall.Name = "Wall"
		wall.CanCollide = false
		wall.CanQuery = false
		wall.CanTouch = false
		wall.Anchored = true
		if x and xmin == nil then
			x = 1 
			xmin = 1 
			wall.Parent = game.ReplicatedStorage
		else
			wall.Size = Vector3.new(x - xmin, 0.5, z - zmin)
		end
		
		wall.Size = Vector3.new(x - xmin, 0.5, z - zmin)
		wall.Position = Vector3.new((x + xmin)/2, y, (z + zmin)/2)
		wall.Parent = nation
		wall.Transparency = 1
		wall.Rotation = Vector3.new()
		local surfaceGui = Instance.new("SurfaceGui")
		surfaceGui.Parent = wall
		surfaceGui.Face = "Top"
		local textLabel = Instance.new("TextLabel")
		textLabel.Rotation = -90
		textLabel.BackgroundTransparency = 1
		textLabel.Parent = surfaceGui
		textLabel.Text = nation.Name
		textLabel.Size = UDim2.new(1,0,1,0)
		textLabel.Font = "SourceSans"
		textLabel.TextScaled = true

		nation.ChildAdded:Connect(function()
			local firstPart = true
			local x, xmin, z, zmin
			
			for i, child in pairs(nation:GetChildren()) do
				if child:IsA("Part") or child:IsA("UnionOperation") then
					if firstPart then
						firstPart = false
						x = child.Position.X
						xmin = child.Position.X
						z = child.Position.Z
						zmin = child.Position.Z
					else
						local xpos = child.Position.X
						local zpos = child.Position.Z

						if xpos > x then
							x = xpos
						elseif xpos < xmin then
							xmin = xpos
						end

						if zpos > z then
							z = zpos
						elseif zpos < zmin then
							zmin = zpos
						end
					end
				end
			end
			
			
			
			wall.Size = Vector3.new(x - xmin, 0.5, z - zmin)
			wall.Position = Vector3.new((x + xmin)/2, y, (z + zmin)/2)
		end)
		nation.ChildRemoved:Connect(function()
			local firstPart = true
			local x, xmin, z, zmin
			for i, child in pairs(nation:GetChildren()) do
				wait(.00001)
				if child:IsA("Part") or child:IsA("UnionOperation") then
					if firstPart then
						firstPart = false
						x = child.Position.X
						xmin = child.Position.X
						z = child.Position.Z
						zmin = child.Position.Z
					else
						local xpos = child.Position.X
						local zpos = child.Position.Z

						if xpos > x then
							x = xpos
						elseif xpos < xmin then
							xmin = xpos
						end

						if zpos > z then
							z = zpos
						elseif zpos < zmin then
							zmin = zpos
						end
					end
				end
			end
			if x and xmin == nil then
				x = 1 
				xmin = 1 
				wall:Destroy()
			else
				x = 1 
				xmin = 1 
				wall.Size = Vector3.new(x - xmin, 0.5, z - zmin)

			end
			
			wall.Position = Vector3.new((x + xmin)/2, y, (z + zmin)/2)
		end)
		if wall.Parent.Name ~= textLabel.Text then
			wall:Destroy()
		end
		
		end
end

	```

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.