Having problems where my block constantly goes a little lower than it should be able to when I scroll back down.
After constant iterations of fix attempts and efforts since June, this is now my last problem I have to fix before I am at a solution
Local script code
local UIS = game:GetService("UserInputService")
local map = {
[1] = {},
[2] = {},
[3] = {},
[4] = {}
}
local currentYOffset = 0
local snapScale = 0.1 -- should be the scale Y value of a block
function round(f)
return tonumber(string.format("%.1f", f))
end
UIS.InputChanged:Connect(function(input, processed)
if not processed then return end
if input.UserInputType == Enum.UserInputType.MouseWheel then
local direction = input.Position.Z
if currentYOffset >= 0 and direction == 1 then
return
end
currentYOffset = math.min(0, currentYOffset + direction*snapScale)
local newMap = {}
for index, line in ipairs(map) do
newMap[index] = {}
for yValue, object in pairs(line) do
object.Position = UDim2.fromScale(object.Position.X.Scale, object.Position.Y.Scale + direction*snapScale)
newMap[index][round(object.Position.Y.Scale)] = object
end
end
map = newMap
end
end)
local function clicked(parentTo, x, y) -- x is not used. Ignore x
local lineNum = tonumber(parentTo.Name)
y = (y - parentTo.AbsolutePosition.Y - game:GetService("GuiService"):GetGuiInset().Y) / parentTo.AbsoluteSize.Y
y = math.floor(y / snapScale + 0.5) * snapScale
y += currentYOffset
y = round(y)
print(y, currentYOffset , y - currentYOffset)
printMapLine(lineNum)
local ry = round(y - currentYOffset )
if map[lineNum][ry] then
print("Note duplicate prevented for Y value: "..y)
return
end
local block = Instance.new("Frame")
block.Size = UDim2.fromScale(1, snapScale)
block.AnchorPoint = Vector2.new(0, 0.5)
block.Position = UDim2.fromScale(0, ry)
block.Parent = parentTo
map[lineNum][ry] = block
end
for _, line in ipairs(script.Parent:GetChildren()) do
if not line:FindFirstChild("MouseGrabber") then continue end
line.MouseGrabber.MouseButton1Down:Connect(function(x,y)
clicked(line, x, y)
end)
end
function printMapLine(line)
for index in pairs(map[line]) do
print("map: "..index)
end
end
testProblem2.rbxl (25.8 KB)