Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

DataStores not saving player teams?

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!

2 comments

0

Are you sure that there are no outputs from the print()s?

0

Yes, there was absolutely nothing in the developer console.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.