I needed a script to create a step from one point to another.
Perhaps it will also help someone.
--Create Codycheck 2024
-- Find Start and End Objects in Workspace
local startStairsPart = workspace:FindFirstChild("Start")
local endStairsPart = workspace:FindFirstChild("End")
if not startStairsPart or not endStairsPart then
error("Start nebo End část nebyla nalezena ve workspace")
end
local startStairsPosition = startStairsPart.Position
local endStairsPosition = endStairsPart.Position
-- Get sizes of Start and End parts
local startSize = startStairsPart.Size
local endSize = endStairsPart.Size
-- Calculate horizontal and vertical distance between Start and End
local totalVector = endStairsPosition - startStairsPosition
local horizontalVector = Vector3.new(totalVector.X, 0, totalVector.Z)
local totalHorizontalDistance = horizontalVector.Magnitude
local totalVerticalDistance = endStairsPosition.Y - startStairsPosition.Y
-- Calculate depth and height of each step
local numberStairs = 20 --- numbers Case
local stepDepth = totalHorizontalDistance / numberStairs
local stepHeight = totalVerticalDistance / numberStairs
local stepDirection = horizontalVector.Unit * stepDepth
-- The width of the stairs changes from Start to End
local startWidth = startSize.X
local endWidth = endSize.X
local widthDifference = (endWidth - startWidth) / numberStairs -- Incremental width change per step
-- Function to create individual parts
local function createPart(name, position, size, color, material, transparency, reflectance, parent, orientation, materialVariant)
local part = Instance.new("Part")
part.Name = name
part.Size = size
part.Anchored = true
part.Position = position
part.Material = material
part.Transparency = transparency
part.Reflectance = reflectance
-- Color setting
if typeof(color) == "BrickColor" then
part.BrickColor = color
elseif typeof(color) == "string" then
part.BrickColor = BrickColor.new(color)
elseif typeof(color) == "Color3" then
part.Color = color
end
-- Setting the orientation if entered
if orientation and typeof(orientation) == "Vector3" then
part.Orientation = orientation
end
-- Adding a materialvariant if specified
if materialVariant then
part.MaterialVariant = materialVariant
end
-- Setting the parent
part.Parent = parent
return part
end
-- Function to create stairs
local function createStairs(startPosition, numberOfSteps, stepWidth, color, material, transparency, reflectance, parent, startOrientation)
local stairsFolder = Instance.new("Folder")
stairsFolder.Name = "Schody"
stairsFolder.Parent = parent
for i = 0, numberOfSteps do
-- Dynamic width adjustment per step
local currentWidth = startWidth + (widthDifference * i)
-- Step position is incremented by depth and height
local stepPosition = startPosition + (stepDirection * i) + Vector3.new(0, i * stepHeight, 0)
-- Create a step part with dynamic width, height, and depth
createPart(
"Schod",
stepPosition,
Vector3.new(currentWidth, stepHeight, stepDepth), -- Width dynamically changes per step
color,
material,
transparency, -- Transparency passed as parameter
reflectance, -- Reflectance passed as parameter
stairsFolder,
startOrientation -- Each step gets the orientation of the Start part
)
end
end
-- Creating stairs in workspace with dynamic width, height, and depth based on Start and End sizes
createStairs(
startStairsPosition,
numberStairs,
startSize.X, -- Initial width of the stairs based on the Start part's width
Color3.fromRGB(130, 138, 61), -- Color
Enum.Material.Concrete, -- Material
0.0, -- Transparency
0.1, -- Reflectance
workspace,
startStairsPart.Orientation -- Pass orientation from Start part
)
Codycheck