I wanted to make that a player picks a color and if the Player leaves the data saves. Wich I think it works but the problem is how do I make it to read the data and put it into the ColorValue of the player?
This is how it looks. (All the values)
I Tried with that:
Snippet Code (in the PlayerAdded function [Line 59 - 72]):
local dataofuser = ds:GetAsync(tostring(plr.UserId).."_UserLocker")
if dataofuser ~= nil then -- anything but nil
print("Found data for " .. plr.Name)
-- RadioOwned.Value = dataofuser[1]
--------------------------------
RadioEquiped.Value = dataofuser[4]
ColorChoosen.Value = Color3.fromRGB(dataofuser[1].R, dataofuser[2].G, dataofuser[3].B)
--BlueCarSkin.Value = dataofuser[1]
--BlueCarSkinO.Value = dataofuser[1]
print(ColorChoosen.Value.."")
print(RadioEquiped.Value.."")
else
print("Replacing no data with new data.")
end
Output Error:
ServerScriptService.DataSaving:65: attempt to index boolean with 'R' - Server - DataSaving:65
This is the DataSaving
Script in the ServerScriptService this is the whole script.
--// SERVICES
local DataStoreService = game:GetService("DataStoreService")
--// VARS
local ds = DataStoreService:GetDataStore("PlayerLocker")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local RadiopassID = 663864800
local function checkGamePass(player, passID)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, passID)
end)
if not success then
warn("Error while checking if player has game pass: " .. tostring(message))
return false
end
return hasPass
end
local function saveData(plr)
local datasave = {}
local folderitemsowned = plr:FindFirstChild("ItemsOwned")
local folderitemequiped = plr:FindFirstChild("ItemsEquiped")
-- table.insert(datasave, checkGamePass(plr, RadiopassID))
--------------------------
table.insert(datasave, 1 , folderitemequiped:FindFirstChild("RadioEquiped").Value)
-- table.insert(datasave, 2 , plr:FindFirstChild("ColorChoosen").Value)
-- table.insert(datasave, 2 , folderitemequiped:FindFirstChild("BlueCarSkinEquiped").Value)
-- table.insert(datasave, 3 , folderitemsowned:FindFirstChild("BlueCarSkinOwned").Value)
ds:SetAsync(tostring(plr.UserId).."_UserLocker", datasave)
end
game.Players.PlayerAdded:Connect(function(plr)
print("executed")
local ColorChoosen = Instance.new("Color3Value", plr)
ColorChoosen.Name = "ColorChoosen"
local FolderOwned = Instance.new("Folder",plr)
FolderOwned.Name = "ItemsOwned"
local RadioOwned = Instance.new("BoolValue",FolderOwned)
RadioOwned.Name = "RadioOwned"
local BlueCarSkinO = Instance.new("BoolValue", FolderOwned)
BlueCarSkinO.Name = "BlueCarSkinOwned"
----------------------------------------------------
local FolderEquiped = Instance.new("Folder", plr)
FolderEquiped.Name = "ItemsEquiped"
local RadioEquiped = Instance.new("BoolValue",FolderEquiped)
RadioEquiped.Name = "RadioEquiped"
local BlueCarSkin = Instance.new("BoolValue", FolderEquiped)
BlueCarSkin.Name = "BlueCarSkinEquiped"
local dataofuser = ds:GetAsync(tostring(plr.UserId).."_UserLocker")
if dataofuser ~= nil then -- anything but nil
print("Found data for " .. plr.Name)
-- RadioOwned.Value = dataofuser[1]
--------------------------------
RadioEquiped.Value = dataofuser[4]
ColorChoosen.Value = Color3.fromRGB(dataofuser[1].R, dataofuser[2].G, dataofuser[3].B)
--BlueCarSkin.Value = dataofuser[1]
--BlueCarSkinO.Value = dataofuser[1]
print(ColorChoosen.Value.."")
print(RadioEquiped.Value.."")
else
print("Replacing no data with new data.")
end
if checkGamePass(plr, RadiopassID) then
-- Player owns the game pass
print("Player owns the game pass")
RadioOwned.Value = true
else
print("Player does not own the game pass")
RadioEquiped.Value = false
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
print(plr.Name .. " is leaving!!")
local datasave = {plr:FindFirstChild("ColorChoosen").Value.R, plr:FindFirstChild("ColorChoosen").Value.G, plr:FindFirstChild("ColorChoosen").Value.B, }
local folderitemsowned = plr:FindFirstChild("ItemsOwned")
local folderitemequiped = plr:FindFirstChild("ItemsEquiped")
-- table.insert(datasave, checkGamePass(plr, RadiopassID))
--------------------------
table.insert(datasave, 4 , folderitemequiped:FindFirstChild("RadioEquiped").Value)
local success,response = pcall(function()
ds:SetAsync(tostring(plr.UserId).."_UserLocker", datasave)
end)
if success then
print("succesfully saved data of " .. plr.Name)
else
warn(response)
end
end)
--game:BindToClose(function()
--for i, p in pairs(game.Players:GetPlayers()) do
--saveData(p)
--end
--end)