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

Identifying if the player clicked on the upper part of the screen?

Asked by 8 years ago

Hello, fellow scripters; I made a script(complicated to explain) I was trying to do an experiment or [how would it work] So i did the 'Button1Down' which whenever you click on any part of your screen it would print something. Normally:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
repeat wait() until player

function button()
print("Down")
end
mouse.Button1Down:connect(button)

Similar to that: The thing i was willing to find out is [how] From the center of your screen, how will i let my output print 'hi' whenever i click the upper part of the screen instead of clicking "anywhere" on my screen. [Only the upper part; starting from the center]

I would appreciate your help, i can't find the proper term for it and was not able to find any results from google from my own words.

0
make an invisible button Async_io 908 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

Good question. Theres actually two ways to do this, one with math and other using GUIs (as NathanTheDeveloper stated).

Math method Simply check if the mouses' Y Value is below half of the viewport size for upper side, or above half for lower side. Essentially, what i mean in 1 simple line:

if mouse.Y < (mouse.ViewSizeY / 2) then /*code*/ end

mouse.ViewSizeY expresses the viewport size - the window screen.

GUI method While this is probably easy to figure out yourself, I'll give you a little hint. Make a GUI Button in the upper half of the screen. This is a complicated workaround and not worth the use; I'd recommend the math method ;).

0
Hey, Intern33t thanks for the respond, With your 'Math method' it worked perfectly! HMNapoleon 35 — 8y
Ad

Answer this question