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

Help with arguments and functions?

Asked by 10 years ago

So I made a function that allows me to make GuiButtons,this function has five arguments:

.Size

.Position

.ButtonSize

.ButtonPositon

.PlayerImage

.Parent

but when I put them in I get an error saying:

Workspace.Script:35: ')' expected near ','

How would I add a UDim value you to this argument?

function CreateButton(Size,Position,ButtonSize,ButtonPosition,PlayerImage,Parent)
----------------------ObjectTable----------------------
local Objects = {}
----------------------Button----------------------
local Button = Instance.new("TextButton",Parent)
Button.Style = Enum.ButtonStyle.RobloxRoundButton
Button.Size = UDim2.new(ButtonSize)
Button.Text = "PlayerName"
Button.Name = "Button"
Button.Position = UDim2.new(ButtonPosition)
table.insert(Objects,Button)
----------------------ButtonUnderImage----------------------
local Buttonunderimage = Instance.new("Frame",Parent)
Buttonunderimage.Style = Enum.FrameStyle.DropShadow
Buttonunderimage.Size = UDim2.new(Size)
Buttonunderimage.Name = "ButtonUnderImage"
Buttonunderimage.Position = UDim2.new(Position)
table.insert(Objects,Buttonunderimage)
----------------------PlayerImage----------------------
local PlayerImage = Instance.new("ImageLabel",Parent)
PlayerImage.BackgroundTransparency = 1
PlayerImage.Image = PlayerImage
PlayerImage.Name = "PlayerImage"
PlayerImage.Position = UDim2.new(Position)
PlayerImage.Size = UDim2.new(Size)
table.insert(Objects,PlayerImage)
----------------------Returninig----------------------
return(Objects)
end
Button = CreateButton(
UDim2.new(0.2,0,0.14, 0), 
UDim2.new(0.02, 0,0.02, 0),
UDim2.new(0.2, 0,0.14, 0),
UDim2.new(0.08, 0,0.13, 0),
"http://www.roblox.com/asset/?id=133035324",
game.Players.Player.PlayerGui.ScreenGui)
--[[UDim2.new(0.2,0,0.14, 0), - Size
    UDim2.new(0.02, 0,0.02, 0)- Position
    UDim2.new(0.2, 0,0.14, 0) -ButtonSize
    UDim2.new(0.08, 0,0.13, 0)- ButtonPosition
    http://www.roblox.com/asset/?id=133035324"-Player Image
    game.Players.Player.PlayerGui.ScreenGui-Parent
--]]
for i,v in pairs (Button) do
    print(v)
end

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Sizes and Positions are UDim2 values.

You have to actually make UDim2 values when you are passing them -- that isn't just something like (1, 2) (Lua doesn't allow this syntax -- because it wouldn't make sense -- which is what is causing your error)

UDim2.new constructor

So, something like this:

CreateButton(
    UDim2.new(0.2, 0, 0.14, 0),
    UDim2.new(0.02, 0, 0.02, 0),
    UDim2.new(0.2, 0, 0.14, 0),
    UDim2.new(0.08, 0, 0.13, 0),
    0,
    game.Player.PlayerGui.ScreenGui
)
0
Thanks for the help but I got another error while putting in the parent parameter kevinnight45 550 — 10y
0
Workspace.Script:36: unexpected symbol near ')' kevinnight45 550 — 10y
1
You have an extra parenthesis on line 32. BlueTaslem 18071 — 10y
Ad

Answer this question