I want to calculate the postion between 2 gui elemnets, but it doesn’t work.
The game wroks the following way: You click on a button and it should go to your cursor until you let go and if the gui element is close to another gui element then make an output. The buttons are inside a frame that has UIGridLayout so while I’m moving the gui part I have to place it inside a folder that is inside the frame to don’t lose its size (since its set to only scale).
Here is my code:
local function movabel(choosen, itemHolder, template, player)
local OriginalParent = choosen.Parent
local Holder
local allowed = false
local mouse = player:GetMouse()
if choosen:IsA("TextButton") then
choosen.MouseButton1Down:Connect(function()
allowed = true
choosen.Parent = OriginalParent.move
while allowed do
---------------------------------------problem---------------------------------------------------------------
TweenService:Create(choosen, TweenInfo.new(0.3, Enum.EasingStyle.Back), {Position = UDim2.new(0,mouse.X,0,mouse.Y)-OriginalParent.Position}):Play() --The OriginalParent.Postion is needed so that the textbutton lines up wtih the mouse, but it doesn't work
if (choosen.AbsolutePosition - OriginalParent.AbsolutePosition - template.AbsolutePosition).Magnitude <= 25 then
---------------------------------------problem---------------------------------------------------------------
if not Holder then
Holder = placeholder:Clone()
Holder.Parent = template
end
else
if Holder then
Holder:Destroy()
end
end
wait()
end
end)
player:GetMouse().Button1Up:Connect(function()
allowed = false
if not Holder then
TweenService:Create(choosen, blok_tweenInfo, {Position = OriginalParent.Position}):Play()
wait(0.298)
choosen.Parent = OriginalParent
else
choosen.Parent = Holder.Parent
Holder:Destroy()
end
end)
end
end
function stock(player)
local PlayerGui = player:FindFirstChild("PlayerGui")
if PlayerGui then
local talkUI = PlayerGui:FindFirstChild("talkUI")
if talkUI then
repeat
local block = TalkingModules.style[math.random(1,#TalkingModules.style)] --list the 1. is a string
local choosen = itemHolder.style:Clone() --sample textButton
choosen.Text = block[1]
choosen.Parent = talkUI.Styles
choosen.Size = choosen.Parent.UIGridLayout.CellSize --to keep size of the
movabel(choosen,itemHolder,choosen.Parent,player)
end
until #choosen_style == MAX_BLOCK_LIMIT --deosn't matters
end
end
end
Ask any questions if this wasn’t clear.