Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make this work after clicking a model and gets removed after clicking another model? (N/A)

To clarify what I said in the Title. I made a script, which was fixed by M39 (thank you), and it worked. So, I then made another one for the second model. Well, when I clicked the model, it poped up the gui, which means it worked. But when I clicked a different one, I hit insert and all of the sudden the one I clicked before still showed up instead of it being removed after I clicked a different one. I want it where if I click something, and when I don't want that, I click a different one which will make the other gui that I clicked before destroyed or remove. This is the script for the first model and for the second model. They are the same, but I did it just in case for like details :D:

Script for Song1:

local song1 = game.Workspace.BoxCD.song1
local disc1 = game.Workspace.PlainDisc2.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() 
            if not inserted then
                inserted = true
                disc1.Texture = "rbxassetid://238387775"
                inserted = false
                screen:Destroy() 
            end
        end)
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked) 

Script for Song2:

local song2 = game.Workspace.BoxCD.song2
local disc2 = game.Workspace.PlainDisc2.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://98698696"
        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() 
            if not inserted then
                inserted = true
                disc2.Texture = "rbxassetid://98698696"
                inserted = false
                screen:Destroy() 
            end
        end)
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked) 

These are separate scripts for each model I put it. What happened is that when I click the first one, it pop ups, but let say they want to see the other ones, well, they click it and then they insert it. Well, after I clicked insert, it worked but the other gui that popped up before was still there and wasn't removed after I clicked a different one. I hope this one explained really good.

2 comments

0

I'm not sure that anyone understands what you are asking. Your explanation of what is happening is not clear.

0

What do you mean? That is very hard to understand, (your explanation)

1 answer

Well you have to make a button and once uou have done that you have to go to "Local Script" and add the click function to make it work!

This discussion is preserved as it was. New answers, comments, and votes are closed.