Hello everyone! This is my first devforum post.
So i have like a bunch of walls/parts in my game, and I want all of them to display their own height on the face of that own part/wall. The problem is, for all the parts that are under 2.1 stud tall, this weirdd glitch seems to be happening where the textlabel only appears when i select it or hover over it. Heres the code I have:
wait(1)
for _, folder in pairs(workspace.Walls:GetChildren()) do
-- Check if the folder is actually a folder
if folder:IsA("Folder") then
-- Iterate through each wall in the folder
for _, wall in pairs(folder:GetChildren()) do
-- Check if the wall is actually a part
if wall:IsA("Part") then
-- Get the height of the wall and round it to the nearest tenth of a stud
local wallHeight = math.round(wall.Size.Y * 10) / 10
-- Create a SurfaceGui to display the height on the face of the right side of the part
local gui = Instance.new("SurfaceGui")
gui.Parent = wall
gui.Face = Enum.NormalId.Right
gui.SizingMode = "PixelsPerStud"
local textLabel = Instance.new("TextLabel")
textLabel.Parent = gui
textLabel.Size = UDim2.new(1, 0, 1, -100)
--textLabel.Position = UDim2.new(0,0,0,-100)
textLabel.Font = Enum.Font.PatrickHand
textLabel.Text = tostring(wallHeight)
--textLabel.Size.Y.Offset = -100
textLabel.TextScaled = false
-- Text size
textLabel.TextSize = 100
-- Make the background of the TextLabel completely transparent
textLabel.BackgroundTransparency = 1
end
end
end
end
I want to get rid of this glitch so the textlabel actually appears without me needing to hover it/select it.
Heres a video of me demonstrating the problem:
(I tried to upload the video here but it failed multiple times).
I added it, and upon closer examination, I didn’t notice any differences at first. However, after some experimentation, I’ve determined that the issue is definitely related to the height of the component. I increased the height of the problematic sections, and the issue was resolved in those cases. (I mentioned this in case it might be useful information.)
wait(1)
for _, folder in pairs(workspace.Walls:GetChildren()) do
if folder:IsA("Folder") then
for _, wall in pairs(folder:GetChildren()) do
if wall:IsA("Part") then
local wallHeight = math.round(wall.Size.Y * 10) / 10
local gui = Instance.new("SurfaceGui")
gui.Parent = wall
gui.Face = Enum.NormalId.Right
gui.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
gui.CanvasSize = Vector2.new(1000, 1000) -- Set an appropriate canvas size
gui.Adornee = wall -- Set the wall as the adornee
local textLabel = Instance.new("TextLabel")
textLabel.Parent = gui
textLabel.Size = UDim2.new(1, 0, 1, -100)
textLabel.Font = Enum.Font.PatrickHand
textLabel.Text = tostring(wallHeight)
textLabel.TextScaled = false
textLabel.TextSize = 100
textLabel.BackgroundTransparency = 1
end
end
end
end
Try decreasing the PixelsPerStud. I don’t see any issues with your current code, so it might be the gui exceeding 10000 pixels (where it tends to bug out).
Correct! Well actually instead of decreasing it I increased it as increasing the number makes the text smaller but the text loads onto more of the walls. But the problem is that some of the walls are so small (0.1 stud high) that i have to set PixelsPerStud to 1000, and when I do that the text appears, but is so small its barely visible. Is there a way I can keep PixelsPerStud high while making my text bigger?