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 ._.

17 comments

0

How is the SurfaceGUI set up (Assuming it's a SurfaceGUI)

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.

0

What is "Holder"?

0

The frame

0

Also, the target is a child of "Holder"

0

What's started?

0

started is changed to true when the game started. It changes to false when the game ends

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.

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.

0

The frame size covers the whole screen.

0

Yes

0

Well I'm not that experienced with guis so I can't really help you, sorry

0

Oh.

0

Maybe try using ZIndex?

0

I said that in the post, it didn't work

0

You’re using InputEnded on the frame, not the ImageButton

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.