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

Trying to make a script that extends the part on one face only (?)

I was the part to extend like this:

[0-----]

But the part keeps extending like this:

[---0---]

Script:

local Part = script.Parent
local Debounce = false

Part.Touched:Connect(function(hit)
	if not Debounce then
		Debounce = true
		local Humanoid = hit.Parent:WaitForChild("Humanoid")
		if Humanoid then
			for i=0, 5 do
				Part.Size = Part.Size + Vector3.FromAxis(Enum.Axis.X)
				wait()
			end
		end
	end
end)

1 answer

you will need to reduce the Position to the half of the size you increased

local Size = 5
local Part = workspace.Part
Part.Size += Vector3.new(0,Size,0)
Part.Position -= Vector3.new(0,Size/2,0) --i dont think you can do both at once

or

local function changeSideSize(side, studs, part)
	if side == "top" then
		part.Size += Vector3.new(0, studs, 0)
		part.Position += Vector3.new(0, studs/2, 0)
	end
	if side == "bottom" then
		part.Size += Vector3.new(0, studs, 0)
		part.Position -= Vector3.new(0, studs/2, 0)
	end
	if side == "left" then
		part.Size += Vector3.new(studs, 0, 0)
		part.Position -= Vector3.new(studs/2, 0, 0)
	end
	if side == "right" then
		part.Size += Vector3.new(0, studs, 0)
		part.Position += Vector3.new(studs/2, 0, 0)
	end
	if side == "front" then
		part.Size += Vector3.new(0, 0, studs)
		part.Position += Vector3.new(0, 0, studs/2)
	end
	if side == "back" then
		part.Size += Vector3.new(0, 0, studs)
		part.Position += Vector3.new(0, 0, studs/2)
	end
end

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