(LAST UPDATE: How to get mouse from plugin - #5 by ptitloup132)
Hello,
I do not know why but when I click on these buttons it’s not working, the buttons are just in an image and the image is in a scrollingframe.
https://gyazo.com/09c64dfb40bfb7469755a0e5dad501ae
To give you a context, I am creating a plugin.
Script:
local image = script.Image.Value
local btn_del = script.DelBtn.Value
local btn_chanepos = script.ChangePosBtn.Value
local frame = image.Parent
local isDragging = false
local startPos
local imageOffset
local isDragging = false
local startPos
local frameSize = frame.AbsoluteSize
local imageOffset = Vector2.new(0, 0)
local function updateImagePosition(mousePosition)
if isDragging then
local newPosition = UDim2.new(0, mousePosition.X - startPos.X + imageOffset.X, 0, mousePosition.Y - startPos.Y + imageOffset.Y)
local minX = 0
local minY = 0
local maxX = frameSize.X - image.Size.X.Offset
local maxY = frameSize.Y - image.Size.Y.Offset
newPosition = UDim2.new(
0, math.clamp(newPosition.X.Offset, minX, maxX),
0, math.clamp(newPosition.Y.Offset, minY, maxY)
)
image.Position = newPosition
end
end
btn_del.MouseButton1Click:Connect(function()
print(1)
if image.Visible then script.Parent:Destroy() end
end)
btn_chanepos.MouseButton1Down:Connect(function()
print(2)
if image.Visible then
isDragging = true
startPos = Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y)
imageOffset = Vector2.new(image.Position.X.Offset, image.Position.Y.Offset)
end
end)
btn_chanepos.MouseButton1Up:Connect(function()
print(3)
if image.Visible then isDragging = false end
end)
plugin:GetMouse().Move:Connect(function()
if isDragging then
updateImagePosition(Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y))
end
end)
Well I did some fixs but just the FORMAT works but not the button cloned…
local image = script.Parent
local frame = image.Parent
local btn_del = image.TB_Delete
local btn_changepos = image.TB_ChangePos
local isDragging = false
local startPos
local frameSize = frame.AbsoluteSize
local imageOffset = Vector2.new(0, 0)
local function updateImagePosition(mousePosition)
if isDragging then
local newPosition = UDim2.new(0, mousePosition.X - startPos.X + imageOffset.X, 0, mousePosition.Y - startPos.Y + imageOffset.Y)
local minX = 0
local minY = 0
local maxX = frameSize.X - image.Size.X.Scale
local maxY = frameSize.Y - image.Size.Y.Scale
newPosition = UDim2.new(
0, math.clamp(newPosition.X.Scale, minX, maxX),
0, math.clamp(newPosition.Y.Scale, minY, maxY)
)
image.Position = newPosition
end
end
btn_del.MouseButton1Click:Connect(function()
print(1)
if image.Visible then image:Destroy() end
end)
btn_changepos.MouseButton1Down:Connect(function()
print(2)
if image.Visible then
isDragging = true
startPos = Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y)
imageOffset = Vector2.new(image.Position.X.Scale, image.Position.Y.Scale)
end
end)
btn_changepos.MouseButton1Up:Connect(function()
print(3)
if image.Visible then isDragging = false end
end)
How I create a node (the image with buttons):
local editor_code = script.Parent.Parent.BlocCode
local blockSpacingX = 10 -- Espacement horizontal entre chaque bloc
local blockSpacingY = 10 -- Espacement vertical entre chaque bloc
local maxColumns = 3 -- Nombre maximal de colonnes avant de sauter une ligne
local print_btn = script.Parent.Node_print
local print_node = editor_code.FORMAT_print
local function getNumberOfBlocks()
local count = -1
for _, child in ipairs(editor_code:GetChildren()) do
if child:IsA("ImageLabel") and not child.Name:find("FORMAT_") then
count = count + 1
end
end
return count
end
local function calculateNextBlockPosition()
local currentCount = getNumberOfBlocks()
local column = currentCount % maxColumns
local row = math.floor(currentCount / maxColumns)
local xPos = column * (print_node.Size.X.Scale + blockSpacingX)
local yPos = row * (print_node.Size.Y.Scale + blockSpacingY)
return UDim2.new(0, xPos, 0, yPos)
end
print_btn.MouseButton1Click:Connect(function()
local number_of_bloc = #editor_code:GetChildren()
local n = print_node:Clone()
n.Parent = editor_code
n.Name = tostring(number_of_bloc) .. "_print"
n.Visible = true
n:FindFirstChild("Node Buttons").Enabled = true
n.Position = calculateNextBlockPosition()
for _, item in ipairs(n:GetChildren()) do
print(item.Name)
end
end)
And by the way I have only “1” or “2” in the output.
local image = script.Parent
local frame = image.Parent
local btn_del = image.TB_Delete
local btn_changepos = image.TB_ChangePos
local isDragging = false
local startPos
local frameSize = frame.AbsoluteSize
local imageOffset = Vector2.new(0, 0)
local function updateImagePosition(mousePosition)
if isDragging then
local newPosition = UDim2.new(0, mousePosition.X - startPos.X + imageOffset.X, 0, mousePosition.Y - startPos.Y + imageOffset.Y)
local minX = 0
local minY = 0
local maxX = frameSize.X - image.Size.X.Scale
local maxY = frameSize.Y - image.Size.Y.Scale
newPosition = UDim2.new(
0, math.clamp(newPosition.X.Scale, minX, maxX),
0, math.clamp(newPosition.Y.Scale, minY, maxY)
)
image.Position = newPosition
end
end
btn_del.MouseButton1Click:Connect(function()
print(1)
if image.Visible then image:Destroy() end
end)
btn_changepos.MouseButton1Down:Connect(function()
print(2)
if image.Visible then
isDragging = true
startPos = Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y)
imageOffset = Vector2.new(image.Position.X.Scale, image.Position.Y.Scale)
end
end)
btn_changepos.MouseButton1Up:Connect(function()
print(3)
if image.Visible then isDragging = false end
end)
plugin:GetMouse().Move:Connect(function()
print("moving")
if isDragging then
updateImagePosition(Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y))
end
end)
To summarize:
The FORMAT_print works to delete but not to move (only “1” and “2”) in the output, and when I create a new node from FORMAT8_print the script does not work.
INFORMATION:
Create Node Localscript:
local editor_code = script.Parent.Parent.BlocCode
local blockSpacingX = 10 -- Espacement horizontal entre chaque bloc (à ajuster selon vos besoins)
local blockSpacingY = 10 -- Espacement vertical entre chaque bloc (à ajuster selon vos besoins)
local maxColumns = 3 -- Nombre maximal de colonnes avant de sauter une ligne
local print_btn = script.Parent.Node_print
local print_node = editor_code.Parent.NodesF.FORMAT_print
local function getNumberOfBlocks()
local count = -1
for _, child in ipairs(editor_code:GetChildren()) do
if child:IsA("ImageLabel") and not child.Name:find("FORMAT_") then
count = count + 1
end
end
return count
end
local function calculateNextBlockPosition()
local currentCount = getNumberOfBlocks()
local column = currentCount % maxColumns
local row = math.floor(currentCount / maxColumns)
local xPos = column * (print_node.Size.X.Scale + blockSpacingX)
local yPos = row * (print_node.Size.Y.Scale + blockSpacingY)
return UDim2.new(0, xPos, 0, yPos)
end
print_btn.MouseButton1Click:Connect(function()
local number_of_bloc = #editor_code:GetChildren()
local n = print_node:Clone()
n.Parent = editor_code
n.Name = tostring(number_of_bloc) .. "_print"
n.Visible = true
n:FindFirstChild("Node Buttons").Enabled = true
n.Position = calculateNextBlockPosition()
end)
Management button node Localscript:
local image = script.Parent
local frame = image.Parent
local btn_del = image.TB_Delete
local btn_changepos = image.TB_ChangePos
local isDragging = false
local startPos
local frameSize = frame.AbsoluteSize
local imageOffset = Vector2.new(0, 0)
local function updateImagePosition(mousePosition)
if isDragging then
local newPosition = UDim2.new(0, mousePosition.X - startPos.X + imageOffset.X, 0, mousePosition.Y - startPos.Y + imageOffset.Y)
local minX = 0
local minY = 0
local maxX = frameSize.X - image.Size.X.Scale
local maxY = frameSize.Y - image.Size.Y.Scale
newPosition = UDim2.new(
0, math.clamp(newPosition.X.Scale, minX, maxX),
0, math.clamp(newPosition.Y.Scale, minY, maxY)
)
image.Position = newPosition
end
end
btn_del.MouseButton1Click:Connect(function()
print(1)
if image.Visible then image:Destroy() end
end)
btn_changepos.MouseButton1Down:Connect(function()
print(2)
if image.Visible then
isDragging = true
startPos = Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y)
imageOffset = Vector2.new(image.Position.X.Scale, image.Position.Y.Scale)
end
end)
btn_changepos.MouseButton1Up:Connect(function()
print(3)
if image.Visible then isDragging = false end
end)
plugin:GetMouse().Move:Connect(function()
print("moving")
if isDragging then
updateImagePosition(Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y))
end
end)
Well I tried to a localscript for all nodes in my scrollingframe “BlocCode” but I do not know how to get the mouse from plugin.
while task.wait(0.5) do
for i, node in ipairs(script.Parent.FLS.BlocCode:GetChildren()) do
if node:IsA("ImageLabel") then
local frame = node.Parent
local isDragging = false
local startPos
local frameSize = frame.AbsoluteSize
local imageOffset = Vector2.new(0, 0)
local function updateImagePosition(mousePosition)
if isDragging then
local newPosition = UDim2.new(0, mousePosition.X - startPos.X + imageOffset.X, 0, mousePosition.Y - startPos.Y + imageOffset.Y)
local minX = 0
local minY = 0
local maxX = frameSize.X - node.Size.X.Scale
local maxY = frameSize.Y - node.Size.Y.Scale
newPosition = UDim2.new(
0, math.clamp(newPosition.X.Scale, minX, maxX),
0, math.clamp(newPosition.Y.Scale, minY, maxY)
)
node.Position = newPosition
end
end
node.TB_Move.MouseButton1Down:Connect(function()
print(1)
if node.Visible then
isDragging = true
startPos = Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y)
imageOffset = Vector2.new(node.Position.X.Scale, node.Position.Y.Scale)
end
end)
node.TB_Move.MouseButton1Up:Connect(function()
print(2)
if node.Visible then isDragging = false end
end)
plugin:GetMouse().Move:Connect(function()
print("moving")
if isDragging then
updateImagePosition(Vector2.new(plugin:GetMouse().X, plugin:GetMouse().Y))
end
end)
end
end
end