How to store multiple datastores

This is the script I currently have, I do not why but it will not work. Please can someone pick out any mistakes I did in this messy bit of code. Thank you for reading.

local DataStoreService = game:GetService(“DataStoreService”)
local playerData = DataStoreService:GetDataStore(“PlayerData”)

local function onPlayerJoin(Player)
local BlackMarketThings = Instance.new(“Folder”)
BlackMarketThings.Name = “BlackMarketThings”
BlackMarketThings.Parent = Player

local SpeedCheck = Instance.new("BoolValue")
SpeedCheck.Name = "SpeedCheck"
SpeedCheck.Parent = BlackMarketThings
SpeedCheck.Value = false

local HealthCheck = Instance.new("BoolValue")
HealthCheck.Name = "HealthCheck"
HealthCheck.Parent = BlackMarketThings
HealthCheck.Value = false

local playerUserId = "Player_ ".. Player.UserId
local SpeedData
local HealthData
local SpeedData = playerData:GetAsync(playerUserId.."-Speed")
local HealthData = playerData:GetAsync(playerUserId.."-Health")
if SpeedData then
	SpeedCheck.Value = SpeedData and SpeedData.SpeedCheck
else
	SpeedCheck.Value = false
end
if HealthData then
	HealthCheck.Value = HealthData and HealthData.HealthCheck
else
	HealthCheck.Value = false
end

end

local function onPlayerLeave(Player)
local success, err = pcall(function()
local playerUserId = "Player_ "…Player.UserId
local speedCheckValue = Player.BlackMarketThings.SpeedCheck.Value
local healthcheckValue = Player.BlackMarketThings.HealthCheck.Value

	local dataToSave = {
		SpeedCheck = speedCheckValue,
		HealthCheck = healthcheckValue
	}
	playerData:SetAsync(playerUserId, dataToSave)

end)
if not success then
	warn("Could not save data, Error message: ", err)
else
	print("Saved 2")
end

end

game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerLeave)

Hello could you please input what the output says about the error? Since it’ll help alot to find the issue

there is no error, the script just simply does not save
(doesn’t display an error)

So does the script print, “Saved 2”?

yes.

30 lett hiuyghgfjgfrduvyljhgbiytfbjhbfuiy

1 Like