Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

why does the UDim2 property of an ImageLabel stay UDim2.new({0, 0},{0, 0})?

Asked by 5 years ago

So, I am currently trying to create a frame using a ModuleScript, and it creates it like it should, but the UDim2 values are ignored and stay UDim2.new({0, 0},{0, 0}) no matter what I do. This is the script I have currently:

local Dialogue = {}

function Dialogue.Create()
    if not game.Players.LocalPlayer.PlayerGui.Game.Graphics.Dialogue:FindFirstChild('Holder') then
        local holder = Instance.new('ImageLabel', game.Players.LocalPlayer.PlayerGui.Game.Graphics.Dialogue)
        holder.Name = "Holder"
        holder.Image = "rbxassetid://2589083797"
        holder.Position = UDim2.new({0, 0},{0.671, 0})
        holder.Size = UDim2.new({1, 0},{0.329, 0})
        holder.BackgroundTransparency = 1
        local text_holder = Instance.new('TextLabel', holder)
        text_holder.Name = "Dialogue"
        text_holder.Size = UDim2.new({0.755, 0},{0.561, 0})
        text_holder.Position = UDim2.new({0.123, 0},{0.093, 0})
        text_holder.BackgroundTransparency = 1
        text_holder.TextColor3 = Color3.new(255, 255, 255)
        text_holder.Font = "Arial"
        text_holder.TextSize = 25
        text_holder.TextWrapped = true
        text_holder.TextXAlignment = "Left"
        text_holder.TextYAlignment = "Top"
    end
end

return Dialogue

Should I just have a pre-made blank version of the GUI part I am trying to make in ReplicatedStorage and just clone or, or is there a way to fix this script?

0
I believe you can make a pre-made blank version of the GUI and implant it in the script, then create a clone of it from the GUI in the script into the PlayerGui I guess fr2013 88 — 5y
0
That is what I am thinking I will have to do, because seems like no matter what I do, the GUI will not change to the size or positions I set in the script -_- AlbatrossVex 7 — 5y
0
So, I was trying to manually change the size from the property window, and it always reverts to 0 on everything... maybe my studio is just broken. Can't change the size or positon of them at all. AlbatrossVex 7 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The problem seems to be on lines where you are sizing and positioning. UDim2.new doesn't take tables as arguments, you need to give it the coordinates as just numbers and not in the table. Calling UDim2.new with improper arguments will position/size the GUI at 0, 0, 0, 0.

UDim2.new(xScale, xOffset, yScale, yOffset)
--NOT this V
UDim2.new({xScale, xOffset}, {yScale, yOffset})

Fixed the problem for me.

Nitpicks

Inconsistency

In some lines you use single quotes '' and in others you used double quotes "". Please choose one or the other.

Deprecated methods

You are using Instance.new second argument, the parent argument, which is deprecated. You can also read here for another reason not to use it.

local imageLabel = Instance.new("ImageLabel")
-- assign all properties
imageLabel.Parent = parent -- assign parent last
--NOT this V
local imageLabel = Instance.new("ImageLabel", parent)

Strings vs enumerations

Use enumerations when applicable rather than strings. Reasons to use them here.

text_holder.Font = Enum.Font.Arial
-- NOT this V
text_holder.Font = "Arial"

Final product

--use single quotes if you want to. I personally use double but it doesn't matter
local Dialogue = {}
local client = game:GetService("Players").LocalPlayer

function Dialogue.Create()
    if not client.PlayerGui.Game.Graphics.Dialogue:FindFirstChild("Holder") then
        local holder = Instance.new("ImageLabel")
        holder.Name = "Holder"
        holder.Image = "rbxassetid://2589083797"
        holder.Position = UDim2.new(0, 0, 0.671, 0)
        holder.Size = UDim2.new(1, 0, 0.329, 0)
        holder.BackgroundTransparency = 1
        holder.Parent = client.PlayerGui.Game.Graphics.Dialogue

        local text_holder = Instance.new("TextLabel")
        text_holder.Name = "Dialogue"
        text_holder.Size = UDim2.new(0.755, 0, 0.561, 0)
        text_holder.Position = UDim2.new(0.123, 0, 0.093, 0)
        text_holder.BackgroundTransparency = 1
        text_holder.TextColor3 = Color3.fromRGB(255, 255, 255)
        -- Color3.new takes arguments from 0-1, use fromRGB 
        text_holder.Font = Enum.Font.Arial
        text_holder.TextSize = 25
        text_holder.TextWrapped = true
        text_holder.TextXAlignment = Enum.TextXAlignment.Left
        text_holder.TextYAlignment = Enum.TextYAlignment.Top
        text_holder.Parent = holder 
    end
end

return Dialogue

Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button, and optionally, give an upvote. It helps both of us out. :) If you have any more questions, then feel free to leave them down in the comments.

Have a fantastic day.

Ad

Answer this question