Hello devs, im having a problem
local index = {}
local function create(y)
for n = 1,7 do ---- Creates 7 buttons and sets its position, parent and inserts it into a table called index
local background = mainScroll.ButtonBackground:Clone()
local button = mainScroll.CopyButton:Clone()
background.Position = UDim2.fromScale(addX + seperate, addY + y)
button.Position = UDim2.fromScale(addX + seperate, addY + y)
addX += 0.1
seperate += 0.04
table.insert(index, button)
background.Parent = mainScroll
button.Parent = mainScroll
end
for i,button in index do -- makes each button inside index have these events
print(i,button)
button.MouseButton1Click:Connect(function()
print("button:",i, button)
if mouseEnterVal.Value == "Drag_On" then
secondButton = button
secondButtonOriginPos = button.Position
print("calling slot change", secondButton)
mouseEnterVal.Value = "Normal"
local goal = {
Position = secondButton.Position,
Size = originSize
}
local secondGoal = {
Size = originSize,
Position = firstButton.Position
}
button.ZIndex = 3
TS:Create(stroke, moveInfo, {Thickness = 0}):Play()
TS:Create(firstButton, moveInfo, goal):Play()
TS:Create(secondButton, moveInfo, secondGoal):Play()
drag.Enabled = false
task.wait(0.3)
button.ZIndex = 2
firstButton.ZIndex = 2
print("destroyed")
once = 0
elseif doubleClick == true and once == 0 then
doubleClick = false
textBox.Text = "Double Clicked!"
mouseEnterVal.Value = "Drag_On"
enterButton = button
firstButton = button
firstButton.ZIndex = 3
stroke.Parent = firstButton
TS:Create(stroke, moveInfo, {Thickness = 5}):Play()
TS:Create(firstButton, moveInfo, {Size = bigSize}):Play()
firstButtonOriginPos = button.Position
drag.Enabled = true
drag.Parent = firstButton
once += 1
task.wait(0.8)
textBox.Text = ""
end
task.spawn(function()
doubleClick = true
task.wait(0.15)
doubleClick = false
end)
if prevConnection then
prevConnection:Disconnect()
prevConnection = nil
end
prevConnection = drag.DragEnd:Connect(function()
if enterButton == nil then
print("enterButton is nil")
TS:Create(firstButton, moveInfo, {Position = firstButtonOriginPos}):Play()
else
print(enterButton)
TS:Create(firstButton, moveInfo, {Position = enterButton.Position}):Play()
TS:Create(enterButton, moveInfo, {Position = firstButtonOriginPos}):Play()
TS:Create(enterButton, moveInfo, {Size = originSize}):Play()
TS:Create(stroke, moveInfo, {Thickness = 0}):Play()
TS:Create(firstButton, moveInfo, {Size = originSize}):Play()
end
mouseEnterVal.Value = "Normal"
drag.Enabled = false
enterButton = nil
task.wait(0.3)
firstButton.ZIndex = 2
once = 0
end)
end)
button.MouseEnter:Connect(function()
print("entered")
local valState = mouseEnterVal.Value
button.BackgroundColor3 = mouseEnterStatesColor[valState]
if mouseEnterVal.Value == "Drag_On" then
enterButton = button
local sizeUp = TS:Create(enterButton, moveInfo, {Size = bigSize})
sizeUp:Play()
end
end)
button.MouseLeave:Connect(function()
button.BackgroundColor3 = mainScroll.CopyButton.BackgroundColor3
enterButton = nil
if mouseEnterVal.Value == "Drag_On" then
enterButton = button
local sizeDown = TS:Create(enterButton, moveInfo, {Size = originSize})
sizeDown:Play()
enterButton = nil
end
end)
end
end
createButtons.MouseButton1Click:Connect(function() -- Creates buttons
addX = 0.07
seperate = 0.01
create(add)
add += 0.29
end)
Check video to see how code runs in game and what is the problem (entered print)
Whats happening is, each time i create a new row of buttons, the older row fires one time more, i dont know how to fix it.
When i place for i,v loop outside function, the buttons wont work