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

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

Asked by 9 years ago

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.

0
I'm not sure that anyone understands what you are asking. Your explanation of what is happening is not clear. AZDev 590 — 9y
0
What do you mean? That is very hard to understand, (your explanation) TheHospitalDev 1134 — 9y

1 answer

Log in to vote
1
Answered by 8 years ago

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!

Ad

Answer this question