So I've been working on an inventory system and a problem came up when I was trying to make a way for people to move items around in their inventories.
What's supposed to happen: When the player clicks on the imagebutton, the image button's position should be set to the mouse's position every time the mouse moves.
What actually happens: The imagebutton's position is successfully set to the mouse's position, but the imagebutton disappears.
Here is script #1 (located in StarterCharacterScripts):
--Variables local Player = game.Players.LocalPlayer local Character = Player.Character local GUI = Player.PlayerGui.Inventory local Box = GUI.Box local Mouse = Player:GetMouse() local Selected = GUI.Selected Target = Selected.Value Selected.Changed:Connect(function(value) Target = value end) Mouse.Move:Connect(function() if Target:IsA("ImageButton") then Target.Visible = true Target.Position = UDim2.new(Mouse.X, 0, Mouse.Y, 0) end end)
Here is script #2 (located within the ImageButton):
local Button = script.Parent local Selected = script.Parent.Parent.Parent.Parent.Selected Button.MouseButton1Click:Connect(function() Selected.Value = Button end)
Here are a few pictures of the hierarchy: !enter image description here!enter image description here The script mentioned earlier (script #2) is the one named "Clicked."
I believe the issue is with either script #1 or the ImageButton's properties. I could be wrong though, I have been trying to get this to work for the past 2 hours with no success.