Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Image button disappears whenever I change its position. How do I fix this?

Asked by 5 years ago

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.

0
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" Divistern 127 — 5y
0
"Selected" is an objectvalue Sandcake85 0 — 5y
0
change the ZIndex greatneil80 2647 — 5y
0
I tried that, unfortunately it still disappears Sandcake85 0 — 5y

Answer this question