I feel kind of stupid asking this considering I’ve done some other research online and it came up as a “basic” part of Lua, but I just haven’t been able to understand it, or any articles on Lua.org.
I know return can break a function, and return to another function if that’s what’s calling it, however sometimes I see people returning arguments, like return a or b and I don’t know what it means or what it does.
Oh, okay, thanks! I’ve seen some rounding functions that use return, and just haven’t been able to grasp it. Does it put a yield or anything, such as if you’re using a RemoteEvent and are waiting for a return from the secondary script, if that makes sense?
For getting a response from the server, I would suggest using RemoteFunctions. But if you are communicating between scripts, just use BindableFunctions or BindableEvents.
I mixed up Bindable and Remote functions, oops.
I’ll make an example here, excuse the lack of indentation, not sure why I can’t put them on here:
Script 1:
function FireEvent()
local variable = 1
PretendThisIsAnEvent:Fire(variable)
print(variable)
end
Script 2:
PretendThisIsAnEvent.Event:Connect(function(variable)
variable = 5
wait(5)
print("ok waited")
return variable -- would the first script wait for the 5 seconds for this return, and then 5 be printed from the first script?
end
I feel so stupid, I kind of forgot about them until Quwanterz’ reply. Didn’t know RemoteFunctions would have a yield though, thanks! I guess I thought RemoteFunctions and Events were the same thing haha.
Yup, that’s why you never want to use a RemoteFunction from Server > Client > Server since exploiters can modify their local script to never return a result and yield your server script.
Good to know, will definitely keep that in mind as I am actually using that in my game for coins. Seems easily exploitable, good thing it isn’t released yet.