I have a game that I just set up to store teams, but the teams will not save for some reason. My script is not outputting anything. Here's the code:
local DataStoreService = game:GetService("DataStoreService") local TeamStored = DataStoreService:GetDataStore("TeamStored") game.Players.PlayerAdded:Connect(function(player) success, err = pcall(function() local team = TeamStored:GetAsync(player.UserId, BrickColor.new(player.TeamColor)) -- Get if success then player.TeamColor = team else print("There was an error getting " .. player.Name .. "'s data") warn(err) end end) game.Players.PlayerRemoving:Connect(function(player) local success2, err2 = pcall(function() TeamStored:SetAsync(player.UserId, BrickColor.new(player.TeamColor)) -- Save end) if success2 then print("Player data successfully saved for " .. player.Name) else print("Player data NOT successfully saved for " .. player.Name) warn(err2) end end) end)
Please help!
Nevermind, I found something while testing "11:56:07.250 - ServerScriptService.DataStores:18: bad argument #1 (Color3 expected, got BrickColor)" So I changed my code to
local DataStoreService = game:GetService("DataStoreService") local TeamStored = DataStoreService:GetDataStore("TeamStored") game.Players.PlayerAdded:Connect(function(player) success, err = pcall(function() local team = TeamStored:GetAsync(player.UserId, BrickColor.new(player.TeamColor.Color)) -- Get if success then player.TeamColor = team else print("There was an error getting " .. player.Name .. "'s data") warn(err) end end) game.Players.PlayerRemoving:Connect(function(player) local success2, err2 = pcall(function() TeamStored:SetAsync(player.UserId, BrickColor.new(player.TeamColor.Color)) -- Save end) if success2 then print("Player data successfully saved for " .. player.Name) else print("Player data NOT successfully saved for " .. player.Name) warn(err2) end end) end)
I changed BrickColor.new(player.TeamColor) to BrickColor.new(player.TeamColor.Color)