How to get parameters from :Wait() on an event?

Hi, I’m trying to make a product purchase script and I was wondering how to do this. I don’t want to make an event connection and then disconnect if I can just wait() for it. But however, I don’t know how to get the parameters, does anyone know how to do this?

Example, turn this:

part.Touched:Connect(function(hit)--hit is parameter
   --asdoaisjdsae
end

Into this?:

part.Touched:Wait() --Where do I put hit?
--aslfhauhfauf
2 Likes
local hit = part.Touched:Wait()
2 Likes
local hit = part.Touched:Wait()

If it returns multiple parameters:

--In this scenario if a 4th parameter is returned, it wont be stored
--So for this example you must know the amount of parameters returned
local a, b, c = event:Wait()

If it returns multiple parameters and you don’t know how many:

--Basically convert the tuple to an array
local params = {event:Wait()}
for i, v in pairs(params) do
	print("params["..i.."] =", v)
end
4 Likes

@Eezby and @NyrionDev thank you guys so much! Now my scripts will be more organized!!

Just so you know, this can be simplified further thanks to generalized iteration:

for i, v in {event:Wait()} do
	print(`params["{i}"] = {v}`)
end

And if the OP is looking for the first parameter, you can use type ascription to coerce the return value to just one value

print(event:Wait()::any) --only the first return value will be printed
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.