Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataStore2 not compatible with Deferred events #142

Open
WEcompany36 opened this issue Aug 4, 2021 · 8 comments
Open

DataStore2 not compatible with Deferred events #142

WEcompany36 opened this issue Aug 4, 2021 · 8 comments
Labels

Comments

@WEcompany36
Copy link

Hello! Recently, Roblox released Deferred Events Beta. However, DataStore2 completely breaks when you are using Deferred Events.

@WEcompany36
Copy link
Author

Here is an image with all of the errors I get with Deferred events enabled:
image

@Kampfkarren
Copy link
Owner

Have you tried this on a basic example instead of an entire game? It's very possible it's your code that is the problem, since very little signals are used in DataStore2.

@WEcompany36
Copy link
Author

Have you tried this on a basic example instead of an entire game? It's very possible it's your code that is the problem, since very little signals are used in DataStore2.

Sorry that it took me a while to get back to you.

Tried it, and there is nothing parented to the Player:
image

local DataStore2 = require(game:GetService("ServerScriptService").DataStore2)
local CombinedDataStore = DataStore2.Combine("SettingsData", "SettingsDataBackup")

local DefaultTable = {
	["LegacyMusic"] = false,
	["MutedMusic"] = false,
}

game:GetService("Players").PlayerAdded:Connect(function(Player)
	local DataStore = DataStore2("SettingsData", Player)
	
	local Data
	
	local Success, Error = pcall(function()
		Data = DataStore:GetTable(DefaultTable)
	end)
	
	if not Success then
		error(Error)
	end
	
	local TimeTrialsData = Instance.new("BinaryStringValue")
	TimeTrialsData.Name = "SettingsData"
	TimeTrialsData.Parent = Player
	
	for DataType, Value in pairs(Data) do
		TimeTrialsData:SetAttribute(DataType, Value)
	end
	
	for DataType, Value in pairs(DefaultTable) do
		if not TimeTrialsData:GetAttribute(DataType) then
			TimeTrialsData:SetAttribute(DataType, Value)
		end
	end
end)

game:GetService("Players").PlayerRemoving:Connect(function(Player)
	local DataStore = DataStore2("SettingsData", Player)
	local DataToSave = {}
	
	for DataType, Value in pairs(Player.SettingsData:GetAttributes()) do
		DataToSave[DataType] = Value
	end
	
	local Success, Error = pcall(function()
		DataStore:Set(DataToSave)
	end)
end)

@Kampfkarren
Copy link
Owner

That's still quite a lot of your own stuff going on.

Please report if you get any warnings from the example in DataStore2's docs.

@Kampfkarren
Copy link
Owner

Kampfkarren commented Aug 7, 2021

Also, for the record, DataStore2:Set can never fail, and it explicitly says in the docs to not use it on PlayerRemoving. You are using DataStore2 completely wrong.

image

@WEcompany36
Copy link
Author

WEcompany36 commented Aug 7, 2021

Also, for the record, DataStore2:Set can never fail, and it explicitly says in the docs to not use it on PlayerRemoving. You are using DataStore2 completely wrong.

image

Thanks for letting me know. I will now fix this.

Edit: Im assuming that I should remove pcalls() also. Am I correct?

@WEcompany36
Copy link
Author

WEcompany36 commented Aug 7, 2021

That's still quite a lot of your own stuff going on.

Please report if you get any warnings from the example in DataStore2's docs.

Still not working even with the simulator example.

Works fine on Intermediate, breaks with deferred, no errors.
Here is the place
DataStore2 Deferred bug.rbxl.zip

@Kampfkarren
Copy link
Owner

Thanks, I'll look into it.

@Kampfkarren Kampfkarren added the bug label Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants