You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
so um my data stores are saving perfectly, it saves all the correct data and stuff. BUT when loading it loads some wrong values -
What is the issue? Include screenshots / videos if possible!
It’s loading old Data for some reason and on rare occasions, it wouldn’t save -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve been solo on this whole thing, this was working like 10 minutes ago and now it’s not, I’ve been using the dev forums for answers.
(the J stands for jetpack and the R stands for Radio)
local Players, DataStoreService = game:GetService("Players"), game:GetService("DataStoreService")
local ColorStorage = DataStoreService:GetDataStore("ColorManager")
local function load(player: Player)
local PlayerUserId = 'Player_'.. player.UserId
local Data = ColorStorage:GetAsync(PlayerUserId)
if Data then
local remoteEvent = player.Parent.Parent.StarterPlayer.StarterCharacterScripts.Radio.ServerToclient
local remoteEvent2 = player.Parent.Parent.StarterPlayer.StarterCharacterScripts.JetPack.ServerToclient
print("load Data")
if Data['PrimaryColorJ'] ~= nil then
local Jcolor1 = Color3.new(unpack(Data['PrimaryColorJ']))
local Jcolor2 = Color3.new(unpack(Data['SecondaryColorJ']))
local Jcolor3 = Color3.new(unpack(Data['ThirdColorJ']))
print(Data)
remoteEvent2:FireClient(player, Jcolor1, Jcolor2, Jcolor3)
end
if Data['PrimaryColorR'] ~= nil then
local Rcolor1 = Color3.new(unpack(Data['PrimaryColorR']))
local Rcolor2 = Color3.new(unpack(Data['SecondaryColorR']))
remoteEvent:FireClient(player, Rcolor1, Rcolor2)
end
else
end
end
local function colortable(player)
local colorsTable = {}
local Found1 = Players:WaitForChild(player.name).Backpack:FindFirstChild("JetPack")
local Found2 = Players:WaitForChild(player.name).Backpack:FindFirstChild("BoomBox")
if Found1 and Found2 then
for _, ColorValues in pairs(Found1.Jetpack.MainParts:GetChildren()) do
colorsTable[ColorValues.Name] = tostring(ColorValues.Color):split(", ")
print(tostring(ColorValues.Color):split(", "))
end
for _, ColorValues in pairs(Found2.BoomBox.MainParts:GetChildren()) do
colorsTable[ColorValues.Name] = tostring(ColorValues.Color):split(", ")
print(tostring(ColorValues.Color):split(", "))
end
return colorsTable
end
end
local function save(player: Player)
print("SavingData")
local colorsaved = colortable(player)
local success, errormessage = pcall(function()
local PlayerUserId = 'Player_'.. player.UserId
print("DataSaved")
ColorStorage:SetAsync(PlayerUserId, colorsaved)
end)
end
Players.PlayerAdded:Connect(function(player: Player)
load(player)
end)
Players.PlayerRemoving:Connect(function(player: Player)
player.CharacterRemoving:Connect(function(Character)
local Check = Players:GetPlayerFromCharacter(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
print("PlayerLeftSaveNow")
save(player)
end)
end)