Here is the code. I use a localscript and just put it in workspace.
s = game.Players.LocalPlayer:GetMouse() s.KeyDown:connect(function(key) key = key:lower() if key == "g" then local f = Instance.new("Part", workspace) f.Anchored = true f.CanCollide = false for i = 1, 500, 0.1 do wait(0.1) f.Size = f.Size + Vector3.new(1, 1, 1) end end end)
Close, first off there are some changes that should be made:
plr = game.Players.LocalPlayer chr = plr.Character s = plr:GetMouse(); s.KeyDown:connect(function(key) key = key:lower() if key == "g" then local f = Instance.new("Part", workspace) f.Anchored = true f.CanCollide = false f.Position = chr.Head.Position + Vector3.new(2,-2,0) --just so it dosent go to (0,0,0) spawn(function() --Create a new thread to handle part seperately for i = 1, 500, 0.1 do wait(0.1) f.Size = f.Size + Vector3.new(1, 1, 1) end end) end 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
:
context = game:GetService("ContextActionService") function newPart() spawn(function() --Create a new thread to handle part seperately for i = 1, 500, 0.1 do wait(0.1) f.Size = f.Size + Vector3.new(1, 1, 1) end end) end context:BindActionToInputTypes( actionName = "newBrick", functionToBind = newPart, false, Enum.KeyCode.G )
For more information on ContextActionService
, visit
http://wiki.roblox.com/index.php?title=ContextActionService_tutorial
Above Code Is Untested