So i’m trying to make it so my “image uploader” creates draggable images, at fisrt the code i got was doing good, but then when it actually creates the image, the code just doesn’t work
i think it’s because that when the cloned image is created, it’s parent is the UIlist, but what i can do about it? have no clue to be honest man
here’s the code i got to do the draggable part:
local UserInputService = game:GetService("UserInputService")
local gui = script.Parent
local dragging
local dragInput
local dragStart
local startPos
local function update(input)
local delta = input.Position - dragStart
gui.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
end
gui.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
dragging = true
dragStart = input.Position
startPos = gui.Position
local connection
connection = input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
connection:Disconnect()
dragging = false
end
end)
end
end)
gui.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
dragInput = input
end
end)
UserInputService.InputChanged:Connect(function(input)
if input == dragInput and dragging then
update(input)
end
end)
local Button = script.Parent
local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:FindFirstChild("ScreenGui")
local Frame = ScreenGui:FindFirstChild("Frame")
local Window = Frame:FindFirstChild("Window")
local ImageSettings = Window:FindFirstChild("ImageSettings")
local IDImage = ImageSettings:FindFirstChild("IDImage")
local Scrolling = Window:FindFirstChild("Scrolling")
local LocalScript = IDImage:FindFirstChild("LocalScript")
ScreenGui.Enabled = true
local function onButtonClick()
local cloned = IDImage:Clone()
ImageSettings.Visible = false
cloned.Parent = Scrolling
end
Button.MouseButton1Up:Connect(onButtonClick)
I looked over it quickly and I do not see where you updated the new images image id. Also instead of making a new image label why not copy the one you are trying to clone and keep the clone draggable and make the old one invisible
–NOT CREATED BY ME, CREDITS GOES TO OWNER OF THE SCRIPT
``
local Drag = script.Parent – gui you want to drag it
gsCoreGui = game:GetService(“CoreGui”)
gsTween = game:GetService(“TweenService”)
local UserInputService = game:GetService(“UserInputService”)
local dragging
local dragInput
local dragStart
local startPos
local function update(input)
local delta = input.Position - dragStart
local dragTime = 0.04
local SmoothDrag = {}
SmoothDrag.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
local dragSmoothFunction = gsTween:Create(Drag, TweenInfo.new(dragTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), SmoothDrag)
dragSmoothFunction:Play()
end
Drag.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
dragging = true
dragStart = input.Position
startPos = Drag.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
dragging = false
end
end)
end
end)
Drag.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
dragInput = input
end
end)
UserInputService.InputChanged:Connect(function(input)
if input == dragInput and dragging and Drag.Size then
update(input)
end
end)
``
oh yeah that’s exactly what i’m doing, but even though i make the clone keep it’s localscript that does all the “dragging stuff” it still doesn’t move, i think it’s the UIlist thats locking it’s position, i was thinking of just changing it’s parent destination, but without the Uilist the clones would be all messy around screen, so then i tought about adding to the script some way to detect whenever it’s being dragged, to change it’s parent, but i have a total of 0 ideas on how to make this
Make a template for the image. so for example a folder with the Template and the drag script in it. Once the button is clicked clone it and put the properties on it.
If you need another drag script the one i use always works for me and never gives me a problem.
local UserInputService = game:GetService("UserInputService")
local SmoothDragToggle
local SmoothDragInput
local SmoothDragStart
local StartPos
local SmoothDragSpeed = 0.175
function SmoothDrag(Frame)
local function UpdateSmoothDragInput(Input)
local Delta = Input.Position - SmoothDragStart
local Position = UDim2.new(StartPos.X.Scale, StartPos.X.Offset + Delta.X, StartPos.Y.Scale, StartPos.Y.Offset + Delta.Y)
game:GetService("TweenService"):Create(Frame, TweenInfo.new(SmoothDragSpeed), {Position = Position}):Play()
end
Frame.InputBegan:Connect(function(Input)
if (Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch) and UserInputService:GetFocusedTextBox() == nil then
SmoothDragToggle = true
SmoothDragStart = Input.Position
StartPos = Frame.Position
Input.Changed:Connect(function()
if Input.UserInputState == Enum.UserInputState.End then
SmoothDragToggle = false
end
end)
end
end)
Frame.InputChanged:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseMovement or Input.UserInputType == Enum.UserInputType.Touch then
SmoothDragInput = Input
end
end)
game:GetService("UserInputService").InputChanged:Connect(function(Input)
if Input == SmoothDragInput and SmoothDragToggle then
UpdateSmoothDragInput(Input)
end
end)
end
SmoothDrag(script.Parent)