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
How is the SurfaceGUI set up (Assuming it's a SurfaceGUI)
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.
What is "Holder"?
The frame
Also, the target is a child of "Holder"
What's started?
started is changed to true when the game started. It changes to false when the game ends
Well, is the frame the same size and position as the imagebutton? An image button is always rectangular, no matter the shape of it.
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.
The frame size covers the whole screen.
Yes
Well I'm not that experienced with guis so I can't really help you, sorry
Oh.
Maybe try using ZIndex?
I said that in the post, it didn't work
You’re using InputEnded on the frame, not the ImageButton
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.