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

How do I change the size of a Part that spawns at a certain position every time I click on a button?

I want to change the size of a Part that spawns at a certain position upon a mouse click. Example: Manual ore spawners at tycoons, I want to change the size of the part that spawns. Please help.

Button = script.Parent

local part = Instance.new("Part", workspace)
part.Size = Vector3.new(1,1,1)
part.Position = script.Parent.Position + Vector3.new(0,5,0)

function makepart()
    
    Instance.new("Part", workspace)

end

Button.ClickDetector.MouseClick:connect(makepart)

1 answer

✓ Accepted answer

You store the new part in a variable, then change the variable.

Also, it is generally better to position an object relative to another object (often a parent or descendant). This allows the same script to be reused and the object repositioned without requiring changes.

local part = Instance.new("Part", workspace)
part.Size = Vector3.new(2, 2, 2)
part.Position = script.Parent.Position + Vector3.new(0, 5, 0)

Edit: Full script:

Button = script.Parent

function makepart()
	local part = Instance.new("Part", workspace)
	part.Size = Vector3.new(2, 2, 2)
	part.Position = script.Parent.Position + Vector3.new(0, 5, 0)
end

Button.ClickDetector.MouseClick:connect(makepart)

2 comments

0

I can't seem to get it working, I re-edited my question's code.

0

No, you put that code in the function, in place of the Instance.new in the modified code.

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