How to infinitely check an if statement

  1. I am trying to make an “if” statement checking if the player has clicked on a part then making the part change positions.

  2. The “if” statement is only checking once.

  3. I have tried using while loops and checking youtube and Dev Forum.

Sorry guys I was defying my own logic and wasn’t using a function while I was doing this.

In this scenario we don’t use an if statement, we use an event.

When the player clicks a part → this happens

Notice the “when” and not “if”.

One way to do it is to use a click detector example scripts on how it can be used in link below:

I made it so that the script is inside the click detector and there’s a function called click that says
script.Parent.MouseClick:Connect(function(click). Thats why I said “if” statement.

The MouseClick event takes the player as an argument(the player who clicked not anything else)
So You can do
ClickDetector.MouseClick:Connect(function(playerwhoclicked)–name it whatever u want
– Here do whatever u want with the part or anything
end)
So here when you are clicking on the part the part will do whatever u instruct
Here is mine
https://gyazo.com/aa98dc61ef2e391a662ee20b00030112