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 9 years ago

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)
0
Try doing it with a Existing Part. Because if you use the "INSTANCE.NEW" It could place it anywhere. woodengop 1134 — 9y
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 — 9y
0
I know that but where would the location of the part go then?? woodengop 1134 — 9y
0
Anyways, tyler46783, what do you think this script is doing what you don't want it to do? Redbullusa 1580 — 9y
0
@TheContinentofEurope The part would go to "game.Workspace". Did you know that "workspace" is shorthand for it? Redbullusa 1580 — 9y

1 answer

Log in to vote
4
Answered by 9 years ago

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 UserInputServiceor 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

Ad

Answer this question