Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

5 comments

0

Try doing it with a Existing Part. Because if you use the "INSTANCE.NEW" It could place it anywhere.

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".

0

I know that but where would the location of the part go then??

0

Anyways, tyler46783, what do you think this script is doing what you don't want it to do?

0

@TheContinentofEurope The part would go to "game.Workspace". Did you know that "workspace" is shorthand for it?

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.