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 "
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.
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)
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
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
end
end)
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.
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