Why is this happening

Hi, this is my code:


local holding = false
UIS.InputBegan:Connect(function(Object)
	if Object.UserInputType == Enum.UserInputType.MouseButton1 then
		if CheckForHolding(script.Parent.Inventory.hola) then
			holding = true
			oldpos = script.Parent.Inventory.hola.Position
			UIS.MouseIconEnabled = false
			while (true) do
				if not holding then
					break
				end
				wait()
				script.Parent.Inventory.hola.Position = calculate()
				--game:GetService('TweenService'):Create(script.Parent.Inventory.hola,TweenInfo.new(0.6,Enum.EasingStyle.Sine),{Position = calculate()}):Play()
				
			end
		end
	end
end)

UIS.InputEnded:Connect(function(Object)
	if Object.UserInputType == Enum.UserInputType.MouseButton1 then
		holding = false
		script.Parent.Inventory.hola.Position = oldpos
			UIS.MouseIconEnabled = true
		for i,v in pairs(script.Parent.Inventory.Slots:GetChildren()) do
			
			if CheckForHolding(v) then
				print('Ok')
					script.Parent.Inventory.hola.Position = v.Position
					holding = false
					break
				end
			end
			
		end
end)

All works fine, but for some reason this happens:
https://gyazo.com/d56e505df43bdc69658bd5dd9b34e02d
Any idea why?

Basically, it goes to ‘v’ position, and goes back to mouse

1 Like

Maybe it’s an issue with the CheckForHolding function that you’ve decided not to show in your code? To me it seems like you’re holding the Grey box but its position is not being set to the slot you’re hovering your mouse over but when you click on a slot the box position changes to the slot, if I’m correct.

It works, 100%.
I am sure, the thing is when you set the position (because it works)
it goes back to mouse

So you’re not supposed to click on the “slots” then the grey box position changes to the “slot”? Is that the issue? I don’t think I can really help with this issue because there are some variables and also functions that you are not showing such as oldpos and calculate function

No, you basically stop pressing the MouseButton1.
Functions has nothing to do, either calculate.
The thing is when you stop pressing it ‘hola’ UI should go to the slot position