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

Why Won't my StringValue Work in my DataStore?

Asked by 4 years ago

I don't know why this isn't working, it prints "SavedSkinEquiped", but then when I rejoin, the value is ""

game.Players.PlayerAdded:Connect(function(player)
    local skinEquiped = Instance.new("StringValue")
    skinEquiped.Name = "SkinEquiped"
    skinEquiped.Parent = player
    local player_data

    pcall(function()
        player_data = skinEquipedDataStores:GetAsync(player.UserId.."-SkinEquiped")
    end)

    if player_data ~= nil then
        skinEquiped.Value = player_data
    else
        skinEquiped.Value = defaultSkinEquiped
    end

    local bindableEvent = Instance.new("BindableEvent")

    game.Players.PlayerRemoving:Connect(function(player)

        pcall(function()
            skinEquipedDataStores:SetAsync(player.UserId.."-SkinEquiped", player.SkinEquiped.Value)
            print("SavedSkinEquiped")
            playersLeft = playersLeft -1
            bindableEvent:Fire()
        end)

    end)

    game:BindToClose(function()
        while playersLeft > 0 do
            bindableEvent.Event:Wait()
        end
    end)

end)

Answer this question