generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Creating instances with an funtion

Previous Thread :: Next Thread 
Falcon is not online. 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
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
28 Oct 2014 08:46 PM
you can call functions with braces? neat
Report Abuse
Falcon is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image