How come this disconnect function works on Studio but not ingame?

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)

These guys lied to me.
Roblox Wiki
DevForum Post

1 Like

It can probably be because you didn’t enable the datastores for studio. You would have to go to the game settings

It is enabled in studio and ingame. Actually I dont think this is even related to datastores

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


https://developer.roblox.com/en-us/api-reference/function/Instance/Destroy


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)

1 Like