I’m trying to save an RGB color to a datastore to allow players in my game to customize the color of their overhead nametag. I’ve found multiple articles on this and tried their solutions but haven’t seemed to get them to work. How my script should work is it gets the RGB Color value of a GUI frame which is the color the player selected and then fires it to the server through a RemoteEvent to save it to the datastore.
Anyone know how to do this? I’m really struggling and would appreciate any help.
Would I do this from the LocalScript or Script? When I try to fire the BackgroundColor3 property in the parameters through the RemoteEvent to the server, it says ‘Attempt to index nil with R’
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("NameColor")
local function saveData(Player, Data)
local DataToSave = Data
local success, err = pcall(function()
DataStore:SetAsync(Player.UserId, DataToSave)
end)
if success then
print("Data has been saved!")
print(DataToSave)
else
print("Data hasn't been saved!")
warn(err)
end
end
game.ReplicatedStorage.SaveNameColor.OnServerEvent:Connect(function(Player, NameColor)
saveData(Player, NameColor)
end)
Local Script:
NameTagColor:WaitForChild("Buy"):WaitForChild("Button").MouseButton1Click:Connect(function()
local NameColor = ColorDisplay
local DataTable = {R = ColorDisplay.BackgroundColor3.R, G = ColorDisplay.BackgroundColor3.G, B = ColorDisplay.BackgroundColor3.B}
game.ReplicatedStorage.SaveNameColor:FireServer(Player, DataTable)
end)
Edit: Wait, I think I’m doing something wrong with the parameters
Is local DataTable = {R = ColorDisplay.BackgroundColor3.R, G = ColorDisplay.BackgroundColor3.G, B = ColorDisplay.BackgroundColor3.B} a table, or am I dumb…?
You can just put the color into a Color3Value, then save the Color3Value. When you need it, take the value from the DataStore, and put it in the Color3Value!
Hmm, I would skip the {R =, G =, B =}, it creates unnecessary data, just instead remember Table[1] is R, Table[2] is G, and Table[3] is B. That is a table though