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:
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.

4 comments
In the first script line 37 when you tried to check if target is an imagebutton, that cannot be checked since target is just a value "Target = Selected.Value"
"Selected" is an objectvalue
change the ZIndex
I tried that, unfortunately it still disappears