How can I detect if an If statement has changed without using a loop?

Hello, I am wondering how I can achieve something similar to this:
If something = this then:Connect(function()

– How can I achieve this without using a loop
– How can I achieve this without looking at the properties of something.
– Is there a way I can create my own custom event such as ".Changed, .MouseClick, ect "

  • Creative Side-B

What condition are you checking, there might be simple ways to do some of them

1 Like

You can still use .Changed! Put a bool value inside the script and then just turn the value to true if u want to fire a function. Then just add that .Changed event in the script. But in my opinion bindable events are better for this.

Use case? Conditionals are evaluated when the statement is reached so you can’t dynamically change the value and expect it to evaluate without a way to reach the statement again, such as with a for loop.

You may want to consider better connection management such that you can connect and disconnect a function (preferably not a lambda) based on your condition and you’ll want a way for that statement to be triggered as well in an event-based manner. That or you can use the conditional in the handler itself to determine if the subsequent code should be ran or not.

In terms of creating your own events, yes there are ways to do that. BindableEvents provide you with an instance-based solution and you can also create pure Luau signals. Veteran developers often prefer to create pure Luau signals for greater event control, object management and because sending and receiving is often better (BindableEvents can’t pass metatables and they create copies of values rather than passing the original by reference).


Checking the player’s position and the parts position and seeing if they’re the same. Hopefully through some kind of event so loops are excluded from the script (apart from getting the players in the server script) I’d like to avoid using tables and dictionary’s too. Thankyou for replying.

Try to use proximity prompts, they fire when ever the player enters and leaves the assigned area

I think you need a while loop for this unless u track when the player moves with UserInputService then send it to the server and grab the position. Isn’t there a function to check when a humanoid walks too? Humanoid.StateChanged

Hello, thankyou. I am looking for a similar system to :GetPropertyChangedSignal but for an if statement (if (player.Character.HumanoidRootPart.Position - Part.Position).Magnitude <= 10 then)

So you want to check if the player is near the part the whole time but without a loop?

Hello, I think you helped me earlier, I have tried the prompt.Shown function changing the “requires line of sight value” too but it’s still broke. Thankyou for replying again :slight_smile:

Why exactly do you not want to use loops?

GetPropertyChangedSignal but for an if statement.

If your use case is checking the player’s distance from an object, consider using Heartbeat. This will allow you to create a handler that’ll be ran every frame. It’s not expensive to run, vector math and accessing magnitude are already very fast.

Heartbeat:Connect(function (dt)
    if magnitude_check_here <= 10 then
        -- Player is in range
    -- else
        -- Player is not in range

I will have a lot of these scripts through out my world and if I have a loop in every one then I would cause performance issues. I also would like to avoid libraries and dictionaries and tables.

Could you take screenshots of what you have done, I wanna get to the bottom of this

Awesome, I will keep that in mind, thanks for your help.

Then why not use a while loop for more than 1 function. I have a while loop that does 3 things at once instead of 3 while loops. Much more efficient.

Heh, haven’t really done much sorry as I don’t know where to start,

It is pretty straight forward,

  1. Add a proximityPrompt instance to you part
  2. Create the script
  3. Reference the ProximityPrompt
  4. enjoy all its power

Oh btw, they are really good when it comes to a lot of interaction parts in your game

I am trying to achieve an interact gui that pops up when your near an object similar to gta v. So these would have different keybinds and managing them through a single loop would be messy and hard to add to. Thankyou for replying though