Problem with datastore, not saving ingame

Hello, i need help about a problem with the datastore. I create a book with monsters descriptions, descriptions are not available, to unlock it, you need to be killed by the monster, and his descrition will be showed :
NOT killed by monster :
image
KILLED by monster :
image

In studio, it save the description and know you have been killed the last time. But when i join my game in game, it reset the book. API is enabled !

Here the script in serverscriptservice :

local DataStoreService = game:GetService("DataStoreService");
local DataStore = DataStoreService:GetDataStore("CreaturesDataStore");

game.Players.PlayerAdded:Connect(function(player)
	
	local Folder = Instance.new("Folder", player)
	Folder.Name = "UnlockedCreatures"
	
	local boolval = Instance.new("BoolValue", Folder)
	boolval.Name = "Angel"
	local boolval2 = Instance.new("BoolValue", Folder)
	boolval2.Name = "CorruptedAngel"
	local boolval3 = Instance.new("BoolValue", Folder)
	boolval3.Name = "Poof"
	local boolval4 = Instance.new("BoolValue", Folder)
	boolval4.Name = "Kadi"
	local boolval5 = Instance.new("BoolValue", Folder)
	boolval5.Name = "Kosoku"
	
	boolval.Value = DataStore:GetAsync(player.UserId) or false
	boolval2.Value = DataStore:GetAsync(player.UserId) or false
	boolval3.Value = DataStore:GetAsync(player.UserId) or false
	boolval4.Value = DataStore:GetAsync(player.UserId) or false
	boolval5.Value = DataStore:GetAsync(player.UserId) or false
end)

game.Players.PlayerRemoving:Connect(function(player)
	DataStore:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("Angel").Value)
	DataStore:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("CorruptedAngel").Value)
	DataStore:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("Poof").Value)
	DataStore:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("Kadi").Value)
	DataStore:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("Kosoku").Value)
end)

Here the LocalScript in the book (an example of monster because it’s the same script for all monsters) :

local Player = game.Players.LocalPlayer

local Frame = script.Parent.Frame

local Value = Player.UnlockedCreatures.Angel

--------

local Desc1 = Frame.Description.Text
local Desc2 = Frame.Description2.Text
local Prob = Frame.Probability.Text
local Title = Frame.Title.Text

--------

local function UpdatePage()
	if Value.Value == true then
		Frame.Normal.ImageColor3 = Color3.fromRGB(255, 255, 255)
		Frame.Description.Text = Desc1
		Frame.Description2.Text = Desc2
		Frame.Probability.Text = Prob
		Frame.Title.Text = Title
	else
		Frame.Normal.ImageColor3 = Color3.fromRGB(0, 0, 0)
		Frame.Description.Text = "???"
		Frame.Description2.Text = "???"
		Frame.Probability.Text = "???"
		Frame.Title.Text = "???"
	end
end

Value.Changed:Connect(function()
	UpdatePage()
end)

UpdatePage()

DataStore:SetAsync works based on keys. Each piece of data you want to save has to have a unique key associated with it. Right now, you are saving UnlockedCreatures to your key, player.UserId and then overwriting it in the next line. DataStore has no way of differentiating the data that you have stored.

A simple way to fix this is to append a string to the back of your UserId for each of your creatures. For example, you could change player.UserId to player.UserId.."-Angel" when saving whether the player has been killed by the Angel.

You will have to change the keys in both the PlayerAdded and the PlayerRemoving functions.

Another way to fix this is to put all the data in a table and save the table to a key like player.UserId.."UnlockedCreatures".

Holy mother of requests, you are abusing the datastore with this.

Like this :

local DataStoreService = game:GetService("DataStoreService");
local DataStoreForAngel = DataStoreService:GetDataStore("AngelDataStore");
local DataStoreForCorruptedAngel = DataStoreService:GetDataStore("CorruptedAngelDataStore");
local DataStoreForPoof = DataStoreService:GetDataStore("PoofDataStore");
local DataStoreForKadi = DataStoreService:GetDataStore("KadiDataStore");
local DataStoreForKosoku = DataStoreService:GetDataStore("KosokuDataStore");

game.Players.PlayerAdded:Connect(function(player)
	
	local Folder = Instance.new("Folder", player)
	Folder.Name = "UnlockedCreatures"
	
	local boolval = Instance.new("BoolValue", Folder)
	boolval.Name = "Angel"
	local boolval2 = Instance.new("BoolValue", Folder)
	boolval2.Name = "CorruptedAngel"
	local boolval3 = Instance.new("BoolValue", Folder)
	boolval3.Name = "Poof"
	local boolval4 = Instance.new("BoolValue", Folder)
	boolval4.Name = "Kadi"
	local boolval5 = Instance.new("BoolValue", Folder)
	boolval5.Name = "Kosoku"
	
	boolval.Value = DataStoreForAngel:GetAsync(player.UserId) or false
	boolval2.Value = DataStoreForCorruptedAngel:GetAsync(player.UserId) or false
	boolval3.Value = DataStoreForPoof:GetAsync(player.UserId) or false
	boolval4.Value = DataStoreForKadi:GetAsync(player.UserId) or false
	boolval5.Value = DataStoreForKosoku:GetAsync(player.UserId) or false
end)

game.Players.PlayerRemoving:Connect(function(player)
	DataStoreForAngel:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("Angel").Value)
	DataStoreForCorruptedAngel:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("CorruptedAngel").Value)
	DataStoreForPoof:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("Poof").Value)
	DataStoreForKadi:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("Kadi").Value)
	DataStoreForKosoku:SetAsync(player.UserId, player:FindFirstChild("UnlockedCreatures"):WaitForChild("Kosoku").Value)
end)

Does it work?

You’re still spamming DataStore with requests. DataStore has a limit to how many you can make in a certain time period. Your requests will get blocked by DataStore if you exceed that limit.

Changing the value with local scripts doesn’t work instead make it via serverscript then it should work.

IT WORK, thank you very much !!!

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