Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

DataStores not saving player teams?

Asked by 4 years ago

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!

0
Are you sure that there are no outputs from the print()s? User#28017 0 — 4y
0
Yes, there was absolutely nothing in the developer console. Dax009YT 6 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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)

Ad

Answer this question