Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
Edited 2 years ago

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
Ad

Answer this question