Im trying to create a miniMap that displays a textlabel based on where doors that can be opened are, sort of like Lethal Companys terminal display.
Im running into an issue in which I dont fully understand how to make the textLabels position match the doors position.
Here is what i am current using to determine the doors:
local function map(n, start, stop, newStart, newStop)
local value = ((n - start) / (stop - start)) * (newStop - newStart) + newStart
if newStart < newStop then
return math.clamp(value, newStart, newStop)
else
return math.clamp(value, newStop, newStart)
end
end
local function CloneMinimapObjects(parentFolder)
local clonedObjects = {}
for _, object in ipairs(parentFolder:GetChildren()) do
if object:IsA("Folder") then
CloneMinimapObjects(object)
elseif object.Name ~= "Roof" then
if (object:IsA("Model") and (object.Name == "KeycardDoubleDoor" or object.Name == "KeycardSingleDoor")) then
clone = TemplateFrame:Clone()
local doorId = object:GetAttribute("DoorId")
print(doorId)
clone.Name = doorId or "Unknown"
clone.DoorId.Text = doorId or "Unknown"
clone.Parent = ViewportFrame
RunService.RenderStepped:Connect(function()
if object.PrimaryPart ~= nil then
local objectPosition = object.PrimaryPart.Position
local x = map(objectPosition.X, -1000, 1000, -ViewportFrame.AbsoluteSize.X / 2, ViewportFrame.AbsoluteSize.X / 2)
local y = map(objectPosition.Z, -1000, 1000, -ViewportFrame.AbsoluteSize.Y / 2, ViewportFrame.AbsoluteSize.Y / 2)
clone.Position = UDim2.new(0.5, x, 0.5, y)
else
return
end
end)
model = object
table.insert(clonedObjects, clone)
else
local clone = object:Clone()
clone.Parent = ViewportFrame
table.insert(clonedObjects, clone)
end
else
local clone = object:Clone()
clone.Parent = ViewportFrame
table.insert(clonedObjects, clone)
end
end
return clonedObjects
end
Basically what this script does is clone anything in my Map Folder and puts it in my Viewport to display while also identifying the doorsId values and cloning the marker into my frame. So far this doesnt work and im not sure why, might be because im not that great at math but, all help is appreciated!