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

Instance.new Part Custom Cframe Value?

So I'm making a game, and I want to have a button that spawns parts? What would I do to customize the part, make a different transparency,meterial,etc. Most importantly though how would I make a custom Cframe, or Vector3 value? Here's the script:

local clickdetector = script.Parent:WaitForChild("ClickDetector")

clickdetector.MouseClick:Connect(function()
local part = Instance.new("Part",game.Workspace)

end)

Hope you can help, thanks!

1 answer

Well, you shouldn't do it like that.

Here is a example.

local button = script.Parent 
local allowNew = script.Parent.BoolValue

button.ClickDetector.MouseButton1Click:connect(function()
	if allowNew then 
			allowNew = false
		wait(.1)
		peggy = instance.new("Part" , workspace)
		peggy.Cframe = Cframe.new(0,0,0) -- change Cframe values for specific position
		allowNew = true
end)

This should work, try it out.

You also wanted transparency and color right? Well that's why you have peggy. Here is an updated for your transparency and color or even material.

local button = script.Parent 
local allowNew = script.Parent.BoolValue

button.ClickDetector.MouseButton1Click:connect(function()
	if allowNew then 
			allowNew = false
		wait(.1)
		peggy = instance.new("Part" , workspace)
		peggy.Cframe = Cframe.new(0,0,0) -- change Cframe values for specific position
		peggy.Transparency = 0.5
		peggy.BrickColor = BrickColor.new("Really red")
		peggy.Material = Enum.Material.wood
		allowNew = true
end)

5 comments

0

So what is allowNew? And what's peggy, i'm new can you explain these? Is peggy what the part will be named?

0

why not put the wait after you create the part

0

You don't need a bool value, just a variable after you define the click detector.(bool variable so you can't spam parts)

0

No, peggy is not the part that will be named. Peggy is just a variable for the instancing function so that on line 9, I can set the position. allowNew is a bool value to prevent spam you don't need a physical object just make a bool var. @Vulk I did put a wait.

0

Ok, thanks!

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