Falcon
|
  |
| Joined: 29 Jul 2007 |
| Total Posts: 801 |
|
|
| 28 Oct 2014 08:40 PM |
Basically all it is supposed to do it make GUI elements in a player
It's making the ScreenGui but not the label there isnt an output
create = function( tab ) local obj = Instance.new( tab[1] ) for i, v in pairs( tab ) do if i ~= 1 then obj[i] = v end end end
local player = game.Players.LocalPlayer repeat wait() until player.Character
local _gamegui = create{ "ScreenGui", Parent = player.PlayerGui, Name = "GameGui" } local _hitscreen = create{ "TextLabel", Parent = _gamegui, Name = "HitScreen", BackgroundColor3 = Color3.new(255, 0, 0), Size = UDim2.new(1,0,1,0), BackgroundTransparency = 0.7 }
|
|
|
| Report Abuse |
|
|
|
| 28 Oct 2014 08:46 PM |
| you can call functions with braces? neat |
|
|
| Report Abuse |
|
|
Falcon
|
  |
| Joined: 29 Jul 2007 |
| Total Posts: 801 |
|
|
| 28 Oct 2014 08:50 PM |
| Yeah you can when its a table and I fixed it |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 28 Oct 2014 10:16 PM |
function create(tab) local object = Instance.new(tab[1]) for p, v in pairs (tab) do pcall(function() object[p] = v end) end return object end
create{"Part", Parent = workspace, BrickColor = BrickColor.new("Bright blue"), Name = "part"}
There was also some service that did exactly this but I forgot what it was called |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 28 Oct 2014 10:19 PM |
Also the reason it works with {} is because you don't need () to run a function with 1 argument (Unless you want to use a number or variable as the argument, basically anything that doesn't separate the function name and the argument In this case { separates it, or in the case below the first " separates it)
print"hi" -->hi |
|
|
| Report Abuse |
|
|
Falcon
|
  |
| Joined: 29 Jul 2007 |
| Total Posts: 801 |
|
|
| 28 Oct 2014 10:28 PM |
| I already fixed it... I forgot to do something in the funtion you're doing to much |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 28 Oct 2014 10:48 PM |
How am I doing to much? I'm hardly doing anything, the only thing I did was add a alternative to if i ~= 1 then, and make it return the object |
|
|
| Report Abuse |
|
|
Falcon
|
  |
| Joined: 29 Jul 2007 |
| Total Posts: 801 |
|
|
| 28 Oct 2014 10:54 PM |
| I didn't mean it like that I meant you could've just returned object |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 Oct 2014 10:55 PM |
Instead of doing possibly a bunch of conditional checks, just take the ClassName as a separate argument.
local create = function(className, properties) local object = Instance.new(className); for key, value in next, properties do object[key] = value; end return object; end;
Something like that, a bit more efficient since it doesn't require a conditional every iteration |
|
|
| Report Abuse |
|
|
128GB
|
  |
| Joined: 17 Apr 2014 |
| Total Posts: 8056 |
|
|
| 28 Oct 2014 10:57 PM |
I found out what it was called
local create = LoadLibrary("RbxUtility").Create
local part = create "Part" {Parent = workspace, BrickColor = BrickColor.new("Bright blue"), Name = "part"} print(part.Name) -->part |
|
|
| Report Abuse |
|
|