Here is the code. I use a localscript and just put it in workspace.
01 | s = game.Players.LocalPlayer:GetMouse() |
02 |
03 |
04 |
05 | s.KeyDown:connect( function (key) |
06 | key = key:lower() |
07 | if key = = "g" then |
08 | local f = Instance.new( "Part" , workspace) |
09 | f.Anchored = true |
10 | f.CanCollide = false |
11 |
12 | for i = 1 , 500 , 0.1 do |
13 | wait( 0.1 ) |
14 | f.Size = f.Size + Vector 3. new( 1 , 1 , 1 ) |
15 | end |
16 | end |
17 | end ) |
Close, first off there are some changes that should be made:
01 | plr = game.Players.LocalPlayer |
02 | chr = plr.Character |
03 | s = plr:GetMouse(); |
04 |
05 | s.KeyDown:connect( function (key) |
06 | key = key:lower() |
07 | if key = = "g" then |
08 | local f = Instance.new( "Part" , workspace) |
09 | f.Anchored = true |
10 | f.CanCollide = false |
11 | f.Position = chr.Head.Position + Vector 3. new( 2 ,- 2 , 0 ) --just so it dosent go to (0,0,0) |
12 | spawn( function () --Create a new thread to handle part seperately |
13 | for i = 1 , 500 , 0.1 do |
14 | wait( 0.1 ) |
15 | f.Size = f.Size + Vector 3. new( 1 , 1 , 1 ) |
16 | end |
17 | end ) |
18 | end |
19 | end ) |
However, the method you are using is highly ineffecient according to the Roblox Wiki. It suggests using UserInputService
or ContextActionService
.
Let's take a look using ContextActionService
:
01 | context = game:GetService( "ContextActionService" ) |
02 |
03 | function newPart() |
04 | spawn( function () --Create a new thread to handle part seperately |
05 | for i = 1 , 500 , 0.1 do |
06 | wait( 0.1 ) |
07 | f.Size = f.Size + Vector 3. new( 1 , 1 , 1 ) |
08 | end |
09 | end ) |
10 | end |
11 |
12 | context:BindActionToInputTypes( |
13 | actionName = "newBrick" , |
14 | functionToBind = newPart, |
15 | false , |
16 | Enum.KeyCode.G |
17 | ) |
For more information on ContextActionService
, visit
http://wiki.roblox.com/index.php?title=ContextActionService_tutorial
Above Code Is Untested