So I’ve been making a randomly generated obby, and I keep having the parts keep going down too far, and I’m wondering if there is a way to restrict how low they can get put. It would be optimal if it wasn’t a huge amount of code required, but I don’t really mind all that much. I’m currently using :
local partTypes = {workspace.SlippyParts, workspace.NormalParts, workspace.KillParts, workspace.FallingParts}
local Colors = {BrickColor.new("Baby blue"), BrickColor.new("Medium stone grey"), BrickColor.new("Really red"), BrickColor.new("Cashmere")}
local maxGap = 4
local maxUpChange = 4
local maxDownChange = 10
local maxXZChange = 5
local maxJumps = 50
local JumpNum
local End
local lastNum = 3
function NewPart(PastPart)
local TypeNum = math.random(#partTypes)
local Part = Instance.new("Part")
Part.Size = Vector3.new(4, 1, 4)
Part.Anchored = true
if TypeNum == 3 and lastNum ~= 3 then
Part.CanCollide = false
end
if lastNum == 3 and TypeNum == 3 then
TypeNum = 2
end
Part.Parent = partTypes[TypeNum]
Part.BrickColor = Colors[TypeNum]
local things = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, -1, -1, -2, -2, -3, -4, -6, -7, -8, -9, -10}
Part.Position = PastPart.Position + Vector3.new(2 + math.random(-1, maxXZChange) + math.random(maxGap), things[math.random(#things)], 2 + math.random(-maxXZChange, maxXZChange))
if JumpNum > (#partTypes[1]:GetChildren() + #partTypes[2]:GetChildren() + #partTypes[3]:GetChildren() + #partTypes[4]:GetChildren()) then
wait(.1)
NewPart(Part)
else
print("Done")
End = Part
end
end
local function obby()
JumpNum = math.random(25, maxJumps)
NewPart(workspace.Start)
end
obby()
I tried doing Part.Position.Y = math.Clamp(etc.), but that didn’t work as Y is not assignable. Any help would be appreciated, have a nice day.
Also the things variable, is simply because it always would favor going down if I didn’t do it that way.