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?
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.
In some lines you use single quotes ''
and in others you used double quotes ""
. Please choose one or the other.
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)
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"
--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