How can I NOT constantly check an if statement?

Hello, I am wondering if this is achievable:
Code:
local function OpenGuiFunction()
– do something
end

if (humanoidRootPart.Position - part.Position).Magnitude <= 10:Connect(openGuiFunction)

if not, is there any other way of doing something like this where I don’t have to do this:

while true do
if (humanoidRootPart.Position - part.Position).Magnitude <= 10 then
– do something
wait()
end

– Creative Side B

1 Like

You can use something known as a repeat-until loop.

read more about it over here:

just scroll down and find the description on repeat loops

Hi, thanks for replying so soon.
I am looking for a way that I don’t use loops as I am making a sort of ‘interactable part’ where it checks if the player is near the part and then opens the gui. So I’d have a lot of these throughout my game for every interactable object. So if there is anyway I can not use a loop of some sort or a loop that doesn’t cause lag and that you can have many scripts of that would be awesome.
– Creative Side B

Do you know by any chance if Run Service is more efficient and/or better for performance than while true do?
– Creative Side-B

You need to use a loop for that I think but if you don’t want lag just make the wait longer.

You dont need multiple scripts to control multiple interactable parts. You can store all of them in a table and use an ipairs loop, which wont cause a lot of lag, also, it will be in a single script.

Hello, thanks for replying, I have experimented with that in the past but it causes lag spikes making the frame rate very unstable.
Thankyou for the reply :slight_smile:

I was thinking that but it would be hard to manage their different purposes and keycodes and the text that pops up like “Press E to enter garage”.
Thankyou for replying.

To manage the different purposes and the text which pops up, you can use a simple dictionary

Would a proximity prompt work for what you are doing?

Hello, I am trying to make a gta v interact gui pop up, thanks for the reply.

Also, as golden said, using UIS, keyCodes, and BillboardGuis is not a viable method of making interactable objects. ProximityPrompts are the best option for making something like interactable parts

1 Like

Great, thankyou for your help! :slight_smile:

You can use the RunService.

For more information, you can go here.
https://developer.roblox.com/en-us/api-reference/class/RunService

Hang on, just did somethinking lol, I have houses loading in and cars, ect so I don’t want to create an update function or something everytime it’s loaded in. Thankyou for your help.

would RunService be better for performance?

Hello. Would this help?

Simplest way currently to achieve this is to use proximity prompts with custom uis

You could just set the style to custom and listen to the triggered function for when the player interacts with the part

Is there a way to make the UI of a proximity prompt not a billboard gui?

I’ll take a look, looks promising, thankyou :slight_smile: