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

So, I am trying to make a block increase size when you press "g". What's wrong with it?

Asked by 10 years ago

Here is the code. I use a localscript and just put it in workspace.

01s = game.Players.LocalPlayer:GetMouse()
02 
03 
04 
05s.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 + Vector3.new(1, 1, 1)         
15    end
16    end
17end)
0
Try doing it with a Existing Part. Because if you use the "INSTANCE.NEW" It could place it anywhere. woodengop 1134 — 10y
0
@TheContinentofEurope You do realize that the second parameter of "Instance.new()" marks the location of the first argument? Also, if the second parameter is not filled, then the first argument's parent is "nil". Redbullusa 1580 — 10y
0
I know that but where would the location of the part go then?? woodengop 1134 — 10y
0
Anyways, tyler46783, what do you think this script is doing what you don't want it to do? Redbullusa 1580 — 10y
0
@TheContinentofEurope The part would go to "game.Workspace". Did you know that "workspace" is shorthand for it? Redbullusa 1580 — 10y

1 answer

Log in to vote
4
Answered by 10 years ago

Close, first off there are some changes that should be made:

01plr = game.Players.LocalPlayer
02chr = plr.Character
03s = plr:GetMouse();
04 
05s.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 + Vector3.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 + Vector3.new(1, 1, 1)         
16    end
17end)
18    end
19end)

However, the method you are using is highly ineffecient according to the Roblox Wiki. It suggests using UserInputServiceor ContextActionService.

Let's take a look using ContextActionService:

01context = game:GetService("ContextActionService")
02 
03function 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 + Vector3.new(1, 1, 1)         
08    end
09end)
10end
11 
12context:BindActionToInputTypes(
13actionName = "newBrick",
14functionToBind = newPart,
15false,
16Enum.KeyCode.G
17)

For more information on ContextActionService, visit http://wiki.roblox.com/index.php?title=ContextActionService_tutorial

Above Code Is Untested

Ad

Answer this question