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

Why is the mouse clicking 2 guis?

Asked by 3 years ago

Hey, I've posted this on DevForums, I'm just reposting it here bc devforums is inactive.

So, I made a guis mode for my aim training game (for mobile users) and when I click a target, it clicks the target and clicks the background (which you are not supposed to click). Can somebody possibly tell me why this is happening? I tried to increase the ZIndex for the target gui, still doesn't work. Heres the code:

game.ReplicatedStorage.OnClick.Event:Connect(function(gui)
        if started then
            totalParts += 1
            gui:Destroy()
            script.Parent.MainGui.Hit:Play()
            local x, y = math.random(1, 9), math.random(1, 9)
            print(x / 10, y / 10)
            points += 20
            accuracy += 1
            displayPoints()
            displayAccuracy()
            createNewPart(UDim2.new(x / 10, 0, y / 10, 0)) -- Creates a new gui
        end
    end)

    script.Parent.MainGui.Holder.InputEnded:Connect(function(input)
        if started then
            if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
                totalParts += 1
                points -= 20
                displayPoints()
                displayAccuracy()
                script.Parent.MainGui.DidNotHit:Play()
            end

        end
    end)

Hope you can help ._.

0
How is the SurfaceGUI set up (Assuming it's a SurfaceGUI) squidiskool 208 — 3y
0
It's a ScreenGUI, it's 2D, and the target is an imagebutton (I use MouseButton1Click to click it) and the background is a frame, so I use InputEnded. DragonSpawner12 61 — 3y
0
What is "Holder"? squidiskool 208 — 3y
0
The frame DragonSpawner12 61 — 3y
View all comments (13 more)
0
Also, the target is a child of "Holder" DragonSpawner12 61 — 3y
0
What's started? squidiskool 208 — 3y
0
started is changed to true when the game started. It changes to false when the game ends DragonSpawner12 61 — 3y
0
Well, is the frame the same size and position as the imagebutton? An image button is always rectangular, no matter the shape of it. squidiskool 208 — 3y
0
The imagebutton's size is 0.1,0,0.1,0, when the frame's size is 1,0,1,0. I set a random position to the image button. DragonSpawner12 61 — 3y
0
The frame size covers the whole screen. squidiskool 208 — 3y
0
Yes DragonSpawner12 61 — 3y
0
Well I'm not that experienced with guis so I can't really help you, sorry squidiskool 208 — 3y
0
Oh. DragonSpawner12 61 — 3y
0
Maybe try using ZIndex? aurich98 86 — 3y
0
I said that in the post, it didn't work DragonSpawner12 61 — 3y
0
You’re using InputEnded on the frame, not the ImageButton OhManXDXD 445 — 3y
0
I'm doing that because I want to check if the player didn't or did press the button. If they press the frame, then I'm not going to give a point. If they press the imagebutton, I am. DragonSpawner12 61 — 3y

Answer this question