I’m using this library from traditionally using the BindableEvent
system, works like a charm, but there’s a weird thing I’d love to know what’s going on…
In this example, the code awaits for a Promise
to complete, it does this by waiting for the PlayerDataLoaded
GoodSignal
event to fire with some business logic present. This code snippet works completely fine.
(the connection variable is stated and initialized in two lines)
return Promise.new(function(resolve)
local connection
connection = PlayerDataService.Events.PlayerDataLoaded:Connect(function(loadedPlayer)
if player == loadedPlayer then
connection:Disconnect()
return resolve(true)
end
end)
end):await()
However, when changing the code to this:
(the connection variable is stated and initialized on one line)
return Promise.new(function(resolve)
local connection = PlayerDataService.Events.PlayerDataLoaded:Connect(function(loadedPlayer)
if player == loadedPlayer then
connection:Disconnect()
return resolve(true)
end
end)
end):await()
I get an attempt to index nil with ‘Disconnect’ error when calling connection:Disconnect()
. What’s the issue with assigning the GoodScript Connection object on just one line?