I added the ImageButton where it says function onButton1Down(mouse)
But what happened, was that it did pop up, but instead the button didn't work after I clicked it and it didn't ger removed or destroyed after I clicked it. Also, on the last line for MouseButton1Down
I don't know how to make it work either since I am using Instance.new()
Please help me out here. I added the explanation to each of them using my knowledge as possible. This is the script:
local song1 = game.Workspace.BoxCD.song1 -- CD Model name local disc1 = game.Workspace.PlainDisc.Decal -- Disc with Decal local gui = game.StarterGui -- GUI local screen = Instance.new("ScreenGui", gui) -- ScreenGUI local image = Instance.new("ImageLabel", screen) --ImageLabel local insert = Instance.new("ImageButton", screen) --ImageButton touch = false -- Just another thing to add if I player touched it inserted = false -- ImageButton says Insert, and it is like the touch = false but instead it inserts or change the decal of the CD function onClicked(clicker) -- Clicker clicked if not touch then -- If it is not touch then touch = true -- Make it true for touch local screen = Instance.new("ScreenGui", clicker.PlayerGui) --Screen gui and where it goes local image = Instance.new("ImageLabel", screen) -- ImageLabel and where it goes local insert = Instance.new("ImageButton", screen) -- ImageButton and goes with screen image.Position = UDim2.new(0, 500, 0, 25) --Position of the Image image.Size = UDim2.new(0, 450, 0, 500) -- Size of it image.Image = "rbxassetid://238387775" --Image ID insert.Position = UDim2.new(0, 830, 0, 485) -- Insert as in ImageButton position insert.Size = UDim2.new(0, 120, 0, 40) -- ImageButton size insert.Image = "rbxassetid://70392447" --ImageButton Image Id touch = false -- And when everything is done with it, the touch is back to false end end function onButton1Down(mouse) --Clicking the ImageButton using the Mouse if not inserted then -- If it is not inserted then inserted = true -- Insert it disc1.Texture = "rbxassetid://238387775" --Changing the decal of the disc to this ID inserted = false -- And then it is done screen:Destroy() --Removes the screen gui image:Destroy() -- Removes image insert:Destroy() -- removes the button end end script.Parent.ClickDetector.MouseClick:connect(onClicked) script.Parent.MouseButton1Down:connect(onButton1Down) -- I am not sure how to use this part when the ImageButton and others happens to be `Instance.new`
OutPut:
21:34:31.556 - MouseButton1Down is not a valid member of UnionOperation
21:34:31.556 - Script 'Workspace.BoxCD.song1.Union.Song1', Line 35
21:34:31.557 - Stack End
You're trying to use MouseButton1Down
on a union part. That's why the script will throw the error that MouseButton1Down
is not a valid member of union part.
What you wanted to do (and this is confirmed in the chat), you wanted to make it so a player clicks the union part with ClickDetector, then add GUI instances to the PlayerGui and connect the ImageButton to an event.
So basically what you want to do is make it one function connecting to the ImageButton after the player clicks on the Union part.
local song1 = game.Workspace.BoxCD.song1 local disc1 = game.Workspace.PlainDisc.Decal touch = false inserted = false function onClicked(clicker) if not touch then touch = true local screen = Instance.new("ScreenGui", clicker.PlayerGui) local image = Instance.new("ImageLabel", screen) local insert = Instance.new("ImageButton", screen) image.Position = UDim2.new(0, 500, 0, 25) image.Size = UDim2.new(0, 450, 0, 500) image.Image = "rbxassetid://238387775" insert.Position = UDim2.new(0, 830, 0, 485) insert.Size = UDim2.new(0, 120, 0, 40) insert.Image = "rbxassetid://70392447" touch = false insert.MouseButton1Down:connect(function() --I like using anonymous functions. So this means that there is a new instance of ImageButton, so we want to know if it gets clicked. if not inserted then inserted = true disc.Texture = "rbxassetid://238387775" inserted = false screen:Destroy() --Since screen holds all Gui objects, everything gets deleted. end end) end end script.Parent.ClickDetector.MouseClick:connect(onClicked) --Last but not least, we want our connection line.
If you need any further explanation on anything, feel free to ask, I know I didn't go into great detail. If this answer helped upvote, if it solved your problem accept the answer. Hope this answer did help.
The output is incredibly self explanatory - Unions do not have a MouseButton1Down event; only GUIs do. I'm assuming that this script is parented to the thing that's being clicked, going by the output.
Also, with your top paragraph - Could you perhaps explain what you're trying to do in a much clearer fashion? I've literally got no clue what you want or what you're trying to do.