I have a function that yields the entire script unless this function/Remote Event returns true. And if it does, it breaks the yield and disconnects the function as well as destroy the Remote Event. It works on studio but not ingame.
Why isn’t it working?
local Profile_Connection
Profile_Connection = ReplicatedStorage.SendProfileData.OnClientEvent:Connect(function(Data)
if Data then
ReplicatedStorage.SendProfileData:Destroy()
Profile_Connection:Disconnect() -- "Error: Attempt to index nil with Disconnect()"
profile.Data = Data
Profile_Stop = true
else
player:Kick(KickMsg)
end
end)
When calling :Destroy() on an Instance, it implicitly disconnects all connections automatically. You don’t need to disconnect connections on an object after it is :Destroy()'ed
Edit: Not sure as to why it works in studio but not ingame though, I dont think it should be erroring at all since the Connection object should still be stored in the variable, but is in a disconnected state (haven’t tested this)