Hey everyone! I’m working on a computer system, where the player can customize it, for example, changing the “OS” color. I’m trying to save these changes that the player does to the system, but I cannot make it work. No errors are displayed on output, which makes me very lost, as it is my first time ever using datastores.
Here’s my workflow:
First of all, the ColorValue (actually a StringValue) on the client receives the new color name, and fires it to the server’s StringValue of the same name: (At PlayerGui)
ColorValue.Changed:Connect(function()
game.ReplicatedStorage.Remotes.ValueChanger:FireServer(game.ReplicatedStorage.Datastore.BobOS_Settings.Color, ColorValue.Value)
local color = ColorValue:FindFirstChild(ColorValue.Value)
for i, v in ipairs(ColorObjects) do
v.ImageColor3 = color.Value
end
end)
Until now, everything seems to work, the server ColorValue.Value
seems to change accordingly to the client one
But here comes the datastoring part: (At ServerScriptService)
From here, I’m completely blinded and have no idea what the problem is, as even the print(ColorValue.Value)
won’t work.
local ColorValue = script.Color
local DataStoreService = game:GetService("DataStoreService")
local ColorDataStore = DataStoreService:GetDataStore("ColorDataStore")
--// ColorValue Player
local function saveColorValue()
local success, error = pcall(function()
ColorDataStore:SetAsync("ColorValue", ColorValue.Value)
end)
if not success then
print("Error saving ColorValue to data store: " .. error)
end
end
local function loadColorValue()
local success, value = pcall(function()
return ColorDataStore:GetAsync("ColorValue")
end)
if success then
ColorValue.Value = value
else
print("Error loading ColorValue from data store: " .. value)
end
end
ColorValue.Changed:Connect(saveColorValue)
ColorValue.Changed:Connect(function()
game.ReplicatedStorage.Remotes.ValueChanger.ClientReceiver:FireAllClients(game.Players.LocalPlayer.PlayerGui.BobOS.Settings.data.Color, ColorValue.Value)
end)
loadColorValue()
wait(6)
print(ColorValue.Value)
And these lines, for when the ColorValue should be loaded: (At PlayerGui)
local ClientServerReceiver = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("ValueChanger"):WaitForChild("ClientReceiver")
ClientServerReceiver.OnClientEvent:Connect(function(object, new)
object.Value = new
end)
Sorry for the long post
But as I said, I’ve never worked with this before, so any help would be highly appreciated!